I want to check if do_action('some_hook')
in WordPress returns/echoes any result for a specific post. I've tried using has_action('some_hook')
but it only checks if 'some_hook'
has any registered handler at global level, it does not check if a specific post has any result for that hook. Can anybody please tell me how to achieve what I want?
I want to check if do_action('some_hook')
in WordPress returns/echoes any result for a specific post. I've tried using has_action('some_hook')
but it only checks if 'some_hook'
has any registered handler at global level, it does not check if a specific post has any result for that hook. Can anybody please tell me how to achieve what I want?
One possible way could be to use PHP's output buffering via ob_start()
like so
ob_start();
do_action('my_hook');
$content = ob_get_contents();
ob_end_clean();
if (empty($content)) {
// no output generated
} else {
// had some output
}
do_action()
does echo the result, provided some some function is hooked into it viaadd_action()
. I'm not sure I understand what you meant? – Faisal Khurshid Commented Feb 4, 2019 at 17:13