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 use Magic Field 2 to display custome field on my page !

However, I would like to be able to hide several field depending on the page ID...

I do not want to use custom post type because my website rely on basic page.

Any idea on how I could do that ? Using javascript perhaps ?

I can't figure out, which hook I should use.

Thanks in advance for your time and patience.

Cheers,

Jk_

share|improve this question
    
a single field within a meta box, or whole meta boxes? –  Milo Apr 27 '12 at 15:10
    
A whole meta box if it's possible. –  Jk_ Apr 28 '12 at 6:46
    
see my answer below. –  Milo Apr 28 '12 at 23:26
add comment

1 Answer

up vote 1 down vote accepted

You can remove meta boxes with the remove_meta_box function:

function wpse50430_remove_meta_boxes() {

    // make sure we're on an admin screen and `post` is set
    if( !is_admin() && !isset( $_GET['post'] ) )
        return;

    if( $_GET['post'] == 99 ): // editing page ID 99
        remove_meta_box( 'pageparentdiv', 'page', 'normal' );
    endif;

}
add_action( 'admin_menu', 'wpse50430_remove_meta_boxes' );

To remove meta boxes added by plugins, you have to find the handle ID. If you use Chrome's developer tools, you can right-click the meta box and look for the ID of the element with class postbox.

share|improve this answer
    
Hi Milo, it is weird because it doesn't work... I got no error, I double check the ID of the meta box. I even tried with an other meta box. Thanks in advance. –  Jk_ Apr 29 '12 at 9:28
    
Ok it works if I replace admin_menu by admin_head ! –  Jk_ Apr 29 '12 at 9:31
    
@Jk_ add_action also has a priority parameter you can change, it's possible the meta boxes were being added after you're trying to remove them in admin_menu. –  Milo Apr 29 '12 at 13:45
    
Thanks mate ! I will look into it. –  Jk_ Apr 29 '12 at 13:50
add comment

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.