• Resolved sdwareham

    (@sdwareham)


    Is it possible to filter the output of a widget when it is added to a post using the the_widget() template tag? I’ve seen methods of filtering widget output but only when they are included in a sidebar using a method such as the one described here:

    https://github.com/philipnewcomer/widget-output-filters

    But what if the widget is not in a sidebar, but instead added with the_widget()?

Viewing 3 replies - 1 through 3 (of 3 total)
  • It doesn’t look like it.
    https://developer.www.ads-software.com/reference/functions/the_widget/
    Maybe there is a filter somewhere in one of the functions that are called, but it’s not the same as filtering the output.

    Moderator bcworkz

    (@bcworkz)

    You could output buffer the widget output, process buffer content, then output that processed content. Depending on what you want to alter, you may be better off extending the widget class and overriding the widget() method as desired, thus creating your own custom widget that does exactly what you want.

    Thread Starter sdwareham

    (@sdwareham)

    Thanks @bcworkz and @joyously! Essentially that is what I’m doing now, using the output buffer to adjust the widget output. I was just making sure there wasn’t an existing filter that might do this as well. As then I might be able to just call that filter once as opposed to using the output buffer each place that widget is called. Thanks for the feedback!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Filter output of the_widget()’ is closed to new replies.