开发者

Wordpress adding selective content filter

开发者 https://www.devze.com 2023-03-26 17:08 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消