Adding boxes to WordPress 2.5+ Write Post panel

I have noticed few inconsistencies in the WordPress 2.6.1 code regarding the methods to add content boxes to the WordPress Write Post panel.

The old way included using

add_action('dbx_post_advanced', 'myplugin_old_custom_box' );
add_action('dbx_post_sidebar', 'myplugin_old_custom_box' );

which would add a box to the Advanced section and Sidebar.

However since version 2.5 dbx_post_sidebar actually adds a box to the end of Advanced section not the sidebar. In return dbx_post_advanced ads code to the beginning of the section.

Proper way to add admin boxes in 2.5+

WordPress 2.5 introduces another function to add the box. It is :

add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ),
'myplugin_inner_custom_box', 'post', 'advanced', 'default' );

Parameters are id, title, callback function for drawing, type ('post', 'page' or 'link' panels), section ('normal', 'advanced') and priority ('high', 'core', 'default', 'low').

In order to add a box to the sidebar you need to use :

add_action('submitpost_box',  'myplugin_sidebar');

The best would be if add_meta_box function would be changed in the following version to also render sidebar boxes. But until then that's how we need to do it.

Continue reading:


Posted in: WordPress
TAGS:, , , , , , , , , , , , , , , , , ,
Leave a comment

One Comment

  1. scribu
    Aug 27th, 2008

    Thanks for this tip. I have already started using it on one of my plugins.

Have your say

Your email is never published nor shared. Required fields are marked *

*
*

This site rewards regular commentators with do-follows links to their site.

Subscribe without commenting

About Vladimir

vladimir prelovac Hi! My name is Vladimir Prelovac. I am a computer engineer by profession and an adventurer by state of mind.

"I would love to change the world, I just don't have the source code yet."

Books by Vladimir

WordPress Plugin Devleopment Book WordPress Plugin Development: Beginner's Guide

Published by Packt Publishing, available online through Amazon. Click the image for more information.

Consulting Services

Professional WordPress solutions based on custom developed plugins and themes

Expert on-site WordPress SEO consulting and an 'out-of-the-box thinking' approach to problems