I am using a version of this (http://www.deluxeblogtips.com/meta-box-script-for-wordpress/) meta box script but I want to be able to limit which edit screen a meta box shows.
For example, if I only want a meta box to show in the “contact” page edit screen, is that possible?
$meta_boxes[] = array(
'id' => 'project-box-1', // meta box id, unique per meta box
'title' => 'Project Box 1', // meta box title
'pages' => array('page'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
Inside your
add_meta_boxex
hook callback function, you will have anadd_meta_box()
call. Wrap that call in a conditional, using data from the$post
global (I’m fairly certain it is available inedit.php
). For example, you could use either the Page ID or slug.Page ID:
Page slug:
Note: you can also target the edit.php page, using the
$pagenow
global, e.g.:However, it might be more efficient just to target the appropriate
add_meta_boxes
hook for your callback. For example, youradd_action()
call probably looks like this:But, you could instead use the
add_meta_boxes_{post_type}
hook, to target Pages specifically:That way, the callback only gets called in the Page post-type context.
See I tend to think a little different than developers. I would make a custom template and associate this with just that template. This way it exists and if you want to add it to another page you use the new custom template.
I don’t have the code in front of me right now.