I was wondering if there were any cut and dry rules to placing meta boxes? I have a meta box for a custom post type for a TV series that holds extra information for said series: when it began airing, genre, etc and I’m debating whether to place it under the editor or on the side. Are there any unofficial rules to what kind of meta box goes where or is it up to the developer’s discretion?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
It is hard to declare best practices here.
The placement depends on the content of the metabox: an editor field would be too narrow usually in the side column; two small checkboxes on the other hand will look lost in the main column.
To understand where which box will be placed, let’s use a small demo plugin:
add_action( 'add_meta_boxes_post', 'register_demo_metaboxes' );
function register_demo_metaboxes()
{
$contexts = array ( 'normal', 'advanced', 'side' );
$priorities = array ( 'high', 'sorted', 'core', 'default', 'low' );
foreach ( $contexts as $context )
foreach ( $priorities as $priority )
add_meta_box(
"demo-$context-$priority", // id
"$context/$priority", // title
'demo_metabox_callback', // callback
NULL, // screen
$context,
$priority
);
}
function demo_metabox_callback( $object, $box )
{
static $count = 1;
print "number " . $count++;
}
side/high and side/sorted will be placed above the Publish box, normal/high immediately after the editor, */low at the end of the screen and probably out of sight.
Some rules I try to follow:
- Do not move the Publish box. Users might not figure out how to move the box down. This can be very annoying.
- Try to understand how often a box might be used. A setting you turn on or off just one time per post should be very low.
- Order by importance: boxes with required fields (price of a product) should be very prominent, a description that will be extracted from the main content if empty, doesn’t have to be visible all the time.
- Some users will move the box out of sight, some might disable it completely. Prepare your callback handlers for that.
- Use
normal/defaultorside/defaultif you are not sure.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
