Remove Filters or hooks from Custom Post Type

During WordPress works sometimes we face few unwanted issues like some plugin has filters that works for all post types that actually bothers. In my short tutorial i would like to show how you can remove those filters from your custom post type very easily by a single piece of code and i believe you gonna love it.

To remove one specific filter(hook) you must have to know the actual filter name. So here is the code that you need to place in your functions.php file :

function wphats_remove_plugin_filters() {
    global $post;

    if ( 'custom_post_type_name' == $post->post_type )
        remove_filter( 'the_content', 'plugin_filter_name' );
}
add_action( 'wp', 'wphats_remove_plugin_filters' );

That’s cool, right ?

But if you like to remove all filters/hooks from a custom post type then just place this code in your funcitons.php file :

function wphats_remove_plugin_filters() {
    global $post;

    if ( 'custom_post_type_name' == $post->post_type )
        remove_all_filters( 'the_content', 'plugin_filter_name' );
}
add_action( 'wp', 'wphats_remove_plugin_filters' );

Please remember, remove_all_filters function removes all of the hooks from filter, and remove_filter remove specific hook name. So if you use ‘remove_all_filters’ you may need to add filter for shortcode

function wphats_remove_plugin_filters() {
    global $post;

    if ( 'custom_post_type_name' == $post->post_type )
        remove_all_filters( 'the_content', 'plugin_filter_name' );
        /* if you want to add shortcode again */
        add_filter("the_content", "do_shortcode");

}
add_action( 'wp', 'wphats_remove_plugin_filters' );

That’s all. Still if you any question. Please drop a message below.

Thanks.

This post has already been read 8091 times!

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

More Posts

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.