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 8108 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.

Share
Published by
Mehedi Hasan

Recent Posts

WP Share A Friend – A Way to Capture Lead

What is Lead Capture: In general sense lead capture designates a process or way of…

5 years ago

Unlimited Modal POPUPS on MouseClick

Introduction Unlimited Modal POPUPS on MouseClick: Everyone knows about popup during site visits and most…

5 years ago

WordPress Pregnancy Calculator Plugin

Brief about Pregnancy Calculator : This WordPress Pregnancy Calculator plugin allows users to display an…

5 years ago

Interactive Service Plugin with Hover Effects VC

Introduction About this Service Plugin: This Visual Composer Service Plugin works as an addon to…

6 years ago

WP Dynamic Query String

Introduction of Dynamic Query String : This plugin allows user to set dynamic query string…

6 years ago

How to make scroll PDF in iFrame for iPAD Safari

There is an occasional bug for iPhone and iPad even they are designed as well and…

7 years ago