我有一个扩展Visual Composer插件的主题,在首页上有一个滑块。滑块将显示来自五个不同客户的五份推荐信。我想在滑块中添加每个推荐信的特色图像作为缩略图。
以下是父主题的简短代码:
function jo_customers_testimonials_slider( $atts ) {
extract( shortcode_atts( array( \'limit\' => 5, "widget_title" => __(\'What Are People Saying\', \'jo\'), \'text_color\' => "#000" ), $atts ) );
$content = "";
$loopArgs = array( "post_type" => "customers", "posts_per_page" => $limit, \'ignore_sticky_posts\' => 1 );
$postsLoop = new WP_Query( $loopArgs );
$content = "";
$content .= \'...\';
$content .= \'...\';
$content .= \'...\';
wp_reset_query();
return $content;
}
add_shortcode( \'jo_customers_testimonials_slider\', \'jo_customers_testimonials_slider\' );
我的职能。php文件:
function jo_customers_testimonials_slider_with_thumbnail( $atts ) {
extract( shortcode_atts( array( \'limit\' => 5, "widget_title" => __(\'What Are People Saying\', \'jo\'), \'text_color\' => "#000" ), $atts ) );
$content = "";
$loopArgs = array( "post_type" => "customers", "posts_per_page" => $limit, \'ignore_sticky_posts\' => 1 );
$postsLoop = new WP_Query( $loopArgs );
$content = "";
$content .= \'...\';
$content .= get_the_post_thumbnail( get_the_ID(), \'thumbnail\' );
$content .= \'...\';
$content .= \'...\';
wp_reset_query();
return $content;
}
add_shortcode( \'jo_customers_testimonials_slider\', \'jo_customers_testimonials_slider_with_thumbnail\' );
理论上,函数来自于我的函数。php文件应该覆盖父主题中的短代码。但当我使用此代码时,似乎什么都没有发生。我做错了什么?
Edit:
尝试了此代码,但仍然无法工作。
function wpa_add_child_shortcodes(){
remove_shortcode(\'jo_customers_testimonials_slider\');
add_shortcode( \'jo_customers_testimonials_slider\', \'jo_customers_testimonials_slider_with_thumbnail\' );
}
add_action( \'after_setup_theme\', \'wpa_add_child_shortcodes\' );
也已更改
add_action( \'after_setup_theme\', \'wpa_add_child_shortcodes\' );
至
add_action( \'init\', \'wpa_add_child_shortcodes\' );
,但结果无差异。
Edit 2 (With Solution):
正在更改
add_action( \'after_setup_theme\', \'wpa_add_child_shortcodes\' );
到
add_action( \'wp_loaded\', \'wpa_add_child_shortcodes\' );
解决了它。