• Hi,

    I have a filter (1st filter) that runs when the theme loads at priority 10 (default)(i assume it does as its in the theme functions theme override of the childtheme).

    Within the theme functions override i have another function that runs on a different filter with priotiy set to 100. Within this function I am adding another filter to modify the 1st filter results but its not firing.

    Are filters available for use in functions and does it look for the function to be before the call?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, you can add, remove, or apply filters from within functions. The filter callback function is checked with is_null() before it is called.

    It may be your priority 100 filter is called too late (in sequence, not due to priority) to affect the first filter.

    Thread Starter everyeurocounts

    (@everyeurocounts)

    ok thanks…you might shed some light on this…the apply_filter is located in a plugin and the function in the theme over-ride is responding to a $_post event on a “view” within a class in the plugin.

    i.e. if the submit info is true, the function fires and within the function the filter is applied, i guess the apply_filters in the plugin is fired before the theme add_filter?

    Thread Starter everyeurocounts

    (@everyeurocounts)

    Moderator bcworkz

    (@bcworkz)

    That is my thinking, but mere existence in a plugin is not any indication that apply_filters() is firing before the theme override. It could go either way, depending on how things are coded. There are other ways the added filter could fail to work, but improper timing is a fairly common reason.

    Debugging filters that fail to fire can be difficult. You might try making a test apply_filters() call from a page template or something. If things work fine from there, it would almost have to be a timing issue.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘using Filters in functions’ is closed to new replies.