WordPress: save output of do_action in variable WordPress: save output of do_action in variable wordpress wordpress

WordPress: save output of do_action in variable


use ob_start() and ob_get_contents() and ob_end_clean() see example #1 on the following page in the PHP manual http://php.net/manual/en/function.ob-get-contents.php

It looks scary the first time, but it works well. Just make sure to always use ob_end_clean() for every time you use ob_start()

ob_start(); // start capturing output.do_action('any_action_you_want');$save_output_here = ob_get_contents(); // the actions output will now be stored in the variable as a string!ob_end_clean(); // never forget this or you will keep capturing output.