0

I need to use shortcodes on widgets and various plugins. For widgets I simply used:

add_filter('widget_title', 'do_shortcode');
add_filter('widget_text', 'do_shortcode');

However I cannot figure out how to activate shortcodes for plugins. I noticed all of them get posts with WP_Query and then $post->post_content. Maybe there is a way to filter post queries? How can I activate shortcodes for all post echoes?

1 Answer 1

0

There is a way to apply that to all post content.

function sc_all_content_wpse_137734($posts) {

  foreach ($posts as &$p) {
    $p->post_content = do_shortcode($p->post_content);
  }

  return $posts;
}
add_filter('the_posts','sc_all_content_wpse_137734');

I would suggest that this is a very, very good way to break things. Plugins and themes will not expect shortcodes to be rendered that early, and the code above will break shortcodes that depend on the $post global, though that could be gotten around with setup_postdata.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.