3

I am using a child theme, and wish to change one of the meta boxes defined in the parent theme. The meta box is for 'pages' only. I tried using the remove_meta_box in my functions.php, but it has no effect:

function remove_parents_box() {
    remove_meta_box( 'id-of-meta-box' , 'page' , 'normal' ); 
}
add_action( 'admin_menu' , 'remove_parents_box' );

Any ideas?

Addition to question: I found that the parent theme uses:

add_action( 'admin_menu', 'lala_create_meta_box_page' );
add_action( 'save_post', 'lala_save_meta_data_page' );

To initiate this meta box. As I wish to create the meta-box with my own code, should I actually remove it by something like:

remove_action( 'admin_menu', 'lala_create_meta_box_page',999 );

And then create my own meta-box?

1 Answer 1

4

Note: This is the merged version between my and @toscho answers.

Explanation (by @toscho)

Use add_meta_boxes_page as action hook.

You can find the hook in wp-admin/edit-form-advanced.php and it displays as:

do_action('add_meta_boxes_' . $post_type, $post);

Solution(s)

Try the following action, which is inside register_post_type() as well.

function wpse59607_remove_meta_box( $callback )
{
    remove_meta_box( 'id-of-meta-box' , 'page' , 'normal' );
}
add_action( 'add_meta_boxes_page', 'wpse59607_remove_meta_box', 999 );

If you know the exact position where the action, that adds the meta box is registered, you can also just remove this one.

function wpse59607_remove_meta_box()
{
    remove_action( 'admin_menu', 'lala_create_meta_box_page' );
}
add_action( '_admin_menu', 'wpse59607_remove_meta_box', 999 );
7
  • Thank you for the brilliant answer! Note: I have continued my question.
    – Nona Man
    Commented Jul 25, 2012 at 13:23
  • The two actions I mentioned are located in a file included from the functions.php.
    – Nona Man
    Commented Jul 25, 2012 at 14:21
  • What is the problem with the include?
    – kaiser
    Commented Jul 25, 2012 at 14:24
  • The include is for the php file with the parent theme's original add_meta_box functions, and the add_action of them which I was trying to remove. The problem is that when using the second solution, which I hoped will remove the whole original action of adding the meta-box in the parent theme, nothing happens.
    – Nona Man
    Commented Jul 25, 2012 at 14:38
  • Try the updated answer.
    – kaiser
    Commented Jul 25, 2012 at 14:43

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.