I am writing a WordPress plugin that does string processing whenever ‘the_author’ filter event is fired. However, some widgets also contain ‘the_author’ event and subsequently my plugin is fired which should not happen. So I am trying to detect if my plugin is called from certain widgets but so far to no avail. One widget that I would like to ignore is called ‘Recent Comments’. I have tried:
function wrap_author($the_author) {
if(!is_active_widget('recent_comments')) {
$the_author = '<span class="CA_author">' . $the_author . '</span>';
return $the_author;
}
}
It could be that I am not using the right name for the widget, I have Googled a lot to find the proper internal name for the Recent Comments Widget but can’t find it so far. Or maybe I should not be using is_active_widget function.
If you just want yours to fire on the “main” content areas then use the
in_the_loop()function to check and see if you’re in a content loop. This will probably get you 99% of the way there but you’ll almost certainly find some edge case that’ll cause frustration 😉This will keep your code from executing at all in a sidebar.