1

Here's how I create my CPT in my parent theme's functions.php:

function my_custom_post_job() {
  ...
  register_post_type('job', $args);
}
add_action('init', 'my_custom_post_job');

I'm trying to unregister this in my child theme's functions.php like so:

add_action('init', 'remove_cpt');
function remove_cpt() {
  remove_action('init', 'my_custom_post_job');
}

What am I doing wrong?

2
  • Child theme functions.php is loaded before parent.
    – Milo
    Mar 30, 2018 at 14:47
  • So that's not doable then?
    – drake035
    Mar 30, 2018 at 17:11

1 Answer 1

3

you cannot remove a hook when you are in the same hook with the same priority.

a solution is to hook the action with a lower priority

add_action('init', 'remove_cpt', 5);
3
  • If the parent theme hook is declared without a priority then the default is 10, so the hook to remove it will need to be higher than 10. Mar 31, 2018 at 5:40
  • if the function remove_cpt is run after my_custom_post_job, it's too late to remove it. my answer has been tested and is shipped with a mmm's certification of conformity and a 5 years warranty ;)
    – mmm
    Mar 31, 2018 at 6:01
  • Oh I see remove_cpt is removing the init hook, not detrgistering the post type. Mar 31, 2018 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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