Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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?

share|improve this question
1  
If i remember correct the the priority must match between both add_action and remove_action calls. –  Bainternet Jun 6 '11 at 22:52
1  
To add some info: Default priority is 10. –  kaiser Jun 7 '11 at 17:07
    
Oh I thought it had to be higher than the action I wanted to remove, I'll try that –  javiervd Jun 7 '11 at 19:04
    
No luck, could it be because the functions file on the child theme gets loaded before the parent theme functions? So I'm trying to remove an action that hasn't been declared yet? –  javiervd Jun 7 '11 at 19:08

4 Answers 4

up vote 3 down vote accepted

Try the following in your child theme functions file.

add_action( 'init', 'remove_mc_projects' );
function remove_mc_projects() {
    remove_action('init', 'mc_projects');
}
share|improve this answer

This helped me.

add_action( 'after_setup_theme','remove_project_custom_init', 100 );

function remove_project_custom_init() {
    remove_action( 'init', 'project_custom_init');
}

Credit goes to www.jasonpaul.net

share|improve this answer

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.

share|improve this answer
    
Formatting perfectly fine. :) Hackish meets it ;) –  kaiser Feb 20 '12 at 15:17
    
brilliant in its simplicity, thanks! –  Piet Jan 24 '13 at 14:07

This worked for me.

function override_parent() {
remove_action( 'init', 'mc_projects', 0 );
}
add_action ('after_setup_theme','override_parent');
share|improve this answer
    
Please add an explanation to your answer: why could that solve the problem? –  toscho Sep 8 at 14:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.