I have created a plugin that uses tokens in the body content to dynamically insert certain content. For example:
%%keyword%%
At page request, that would get replaced with a keyword specified in the incoming URL.
I would like to be able to use these tokens in a widget and have them processed the same, but my plugin only knows about the_content
and I haven’t been able to figure out, how to tell it to parse the content of widgets as well, before final page render.
How would this be done? I suppose it can be done more easily with shortcodes, but I’d like to stay consistent with my token usage.
Appreciate any suggestions!
EDIT:
Minutes after posting I found this post which has given me what I need:
Is There A Hook To Process The Content Of The Text Widget?
Thanks anyway all!
The filter you’re looking for is
widget_text
. From the Codex:The following code will allow you to make replacements in all Widgets, on all strings present in their $instance arrays.
It’s a bit more advanced but it’s WHAT you really need.
And the same thing with array_walk_recursive() which recurses objects also:
Have fun!