Is it possible? "do_action" within shortcode

Does anyone know of a way to include a do_action within a shortcode? I’m guessing it may not be possible since shortcodes need to return data and do_action prints out data… but, it would be nice if there was a way!

…or, if anyone know of a crazy alternative to accomplishing the same thing, that would be cool too.


It’s really easy actually, you just need to place the contents of the short code in an output buffer:

function your_shortcode($atts, $content = null) {
      return ob_get_clean();
add_shortcode('shortcode_name', 'your_shortcode');

Sweet! I’ll give that a try. Thanks again for all the help. You’ve been a great resource for me. You’ll be getting a new subscriber to your blog soon!

Glad to help!

Thank you very much kind person!

This topic was automatically closed after 36 hours. New replies are no longer allowed.