add_action('add_meta_boxes', 'add_testbox');
function add_testbox() {
add_meta_box( 'testmetabox', 'Test Meta Box', 'testmetabox_content', 'post', 'side', 'low');
}
function testmetabox_content() {
echo "hi";
}
You can drag and drop the box into the spot you want it to display.
Make sure you always wrap the add_meta_box()
function in another function, then hook that in like I showed. If you call add_meta_box()
outside the function, you’ll get a fatal error.
This example is for WordPress 3.0 and above. As the WordPress Codex shows, the ‘add_meta_boxes’ hook I used was added in WP 3.0. If you’re using an older version of WordPress, (which you shouldn’t be), use ‘admin_init’ instead of ‘add_meta_boxes’.