Remove or override functions attached to a specified filter hook

There are situations when a plugin/theme use some filter hooks to change the default behaviour of the wordpress functionality and then forgets to remove the change they have applied or sometimes intentionaly because of such requirement. But this affects all over the website and causes problem, where as we want to use the default behaviour and not this changed one.

Now, the question is ” how can we override a funtion that is already applied for a particular filter hook “.

Option 1: remove_filter

If we know which function is called for a particular hook which is causing the issue, then we can use

Option 2: remove_all_filters

Remove all the call_back functions those are added for a particular filter hook.(Helpfull when we don’t know the functions that are applied for a particular filter)

But again,this might cause issues as we are completly removing all the functions(whatever is the priority) for that filter hook. There is a solution too.

Option 3: add_filter with high priority

Call a custom defined function with high priority for the filter hook.
Default priority number is 10. So I am passing 99 as the $priority parameter.

Don’t forget to remove the filter once you are done with your task.


Simple example to understand the exact situation:

* A plugin uses a function to change the default sorting order of posts.

* Now we have a widget(say Popular Posts by Comments count) which fetches and displays the most commented posts.

* Now the problem is that the Popular Posts by Comments count widget does not display the posts as intended i.e. orderby most commented. 🙁


Write a function which will be called to override the previous funtion(mentioned above). Now call this function for that filter hook with high priority. 🙂

* So the modified code will be as below:

Hope this post will help somebody someday !! 🙂