Wordpress adding selective content filter
Is it possible to know if a widget is what is actually executed(displayed on sidebar) during get_the_content or the_content content filters?
What I want to do is to create a content filter that will work selectively - only if widget is executing - I do not want to affect other content only content within widget, but before any other filter is applied (priority < 10 ...). And it would开发者_如何学JAVA be nice to remove content filter after widget finished execution.
There are nice functions like is_page is_category, ... but no is_sidebar or someting like that.
I did try to add & remove filter within widget display function, but it seems it is not possible to add filter like that.
You can add your handler to get_sidebar
action, set some global variable to true there, and then reset it at the end of your function. Not an elegant solution though. Another way is to check debug_backtrace result for get_sidebar
function presence, but I am almost sure it will work really slow.
精彩评论