I would like to modify the shortcode output of a WordPress plugin.
I have tried the following:
$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;
}
Unfortunately the filter isn't applied on the shortcode output.
If I do it like this to override the shortcode and to modifiy the output there will be a infinite loop caused by the do_shortcode function:
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');
Did I do something wrong or is there another/better way to modify the output of a shortcode?
WordPress 4.7 introduced a new filter, do_shortcode_tag, to do exactly this. https://www.shawnhooper.ca/2017/01/do-shortcode-tag/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With