Unregister post type from child theme

I’m trying to unregister a post type from a child theme but I haven’t been able to do so, the code in the funcions.php file on the parent theme is something like this:

add_action( 'init', 'mc_projects' );
function mc_projects() {
    register_post_type( 'project', array(
        // Default options....
    ) );

}

What I tried to do in my child theme was to remove the mc_project action from the init hook like this:

Read More
remove_action('init', 'mc_projects', 11);

But it didn’t work, even when I set the priority to some higher value, am I doing something wrong?

Related posts

Leave a Reply

5 comments

  1. Try the following in your child theme functions file.

    add_action( 'init', 'remove_mc_projects' );
    function remove_mc_projects() {
        remove_action('init', 'mc_projects');
    }
    
  2. Here’s another solution, abeit a bit hackish –

    In my parent theme, my custom post type is created like so:

    if (!(function_exists('my_post_type')))
    {
        function my_post_type()
        {
                ...
        }
    }
    

    Then, in my child theme, I simply re-declare the function as empty –

    function my_post_type() { }
    

    Hope this helps! This is my first contribution to a forum like this so please excuse any formatting rules I’ve broken.

  3. no one above not work for me in WordPress 4.9.7 but this solve my problem

    function delete_post_type(){
      unregister_post_type( 'portfolio' );
    }
    add_action('init','delete_post_type', 100);