remove_filter function in WordPress

Motivation: In a specific website I am using the simplex theme. If one tries to place a static page as home instead of the blog, simplex keeps showing the Home page.
Solution: as you can see, people have already reported this. But in the current version of the theme the line is introduced in functions.php and functions are not really overridden, they can be just replaced.
In the codex it is described how to remove actions and filters but it turned out that the solution didn’t work for me. As usually, it was really easy but cost me a bit to figure out:

1
2
3
4
5
6
function unhook_simplex_function() {
    if(has_filter( 'wp_nav_menu_items', 'simplex_nav_menu_items' )){
        remove_filter( 'wp_nav_menu_items', 'simplex_nav_menu_items' );
    }
}
add_action('init','unhook_simplex_function');
function unhook_simplex_function() {
    if(has_filter( 'wp_nav_menu_items', 'simplex_nav_menu_items' )){
        remove_filter( 'wp_nav_menu_items', 'simplex_nav_menu_items' );
    }
}
add_action('init','unhook_simplex_function');

Instead of calling the remove_filter function directly in my functions.php I just added an action that calls the function that will remove the filter from the ‘init’.

Leave a Reply

Your email address will not be published. Required fields are marked *

*