小编Ph4*_*t0m的帖子

将过滤器应用于WordPress短代码输出

我想修改WordPress插件的简码输出。

我尝试了以下方法:

$myShortcode = do_shortcode('[print_responsive_thumbnail_slider id="1"]');
echo apply_filters('new_shortcode_filter',$myShortcode);


add_filter('new_shortcode_filter','new_shortcode_filter_callback');

function new_shortcode_filter_callback($myShortcode){
    //modify content right here

    return $modifiedContent;
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,该过滤器未应用于短代码输出。

如果我这样做是为了覆盖简码并修改输出,那么do_shortcode函数将导致无限循环:

function update_shortcode_slider_content() {
    $sliderContent = do_shortcode('[print_responsive_thumbnail_slider id="1"]');;
    //some magic

    return $modifiedSliderContent;
}
add_shortcode('print_responsive_thumbnail_slider', 'update_shortcode_slider_content');
Run Code Online (Sandbox Code Playgroud)

我做错了什么吗,还是有另一种/更好的方式来修改简码的输出?

wordpress shortcode

3
推荐指数
1
解决办法
5053
查看次数

标签 统计

shortcode ×1

wordpress ×1