0

I am trying to add a menu box to Pages > Pages or Pages > Add New, basically whenever they access a page, be it to edit an existing page or add a new one, I would like to add a menu box under the Page Attributes box on the right, or anywhere on those pages that I can add a input form into to work in conjunction with the plugin I am trying to build.

I am very very new to wordpress plugin development, so please forgive my ignorance on the subject, any learning materials or good resources on the subject would also be greatly appreciated!

Thanx in advance!

2

3 Answers 3

1
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'.

1
  • Thank you, that is perfect, I just had to change the type from post to page and that did the trick!
    – Odyss3us
    Commented Jan 24, 2011 at 20:27
1

actually quite simple - you can use add_meta_box ( see http://codex.wordpress.org/Function_Reference/add_meta_box ) to add as many different meta boxes as you like to your post type (page in your case).

This allows you to render custom html in your box, just remember to use the save_post action to intercept your post data.

3
  • Thank you for the help! That did the trick, and I'll have a look at save_post. I wish I could choose more than one answer though. :/
    – Odyss3us
    Commented Jan 24, 2011 at 20:29
  • @user2632 Don't let this prevent you from actually choosing one (as accepted) :)
    – Michal Mau
    Commented Jan 25, 2011 at 5:21
  • Haha no ofcourse not. :)
    – Odyss3us
    Commented Jan 25, 2011 at 8:06
1

Updated. after your comment i read the question again and i saw that i was wrong with my answer and your title was miss leading.

what you are looking for is call Meta Box. there are about 100 of questions around here that show just how to add one to your edit screen but if you are just starting out i would recommend trying the tut here http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html

2
  • Thank you for the reply, although that seems to be adding in a sub menu for the left hand admin sidebar, where as I am trying to add a menu inside of the post.php page underneath the Page Attributes box on the right. Any idea on how I can add that in? Or am I missing something?
    – Odyss3us
    Commented Jan 24, 2011 at 20:21
  • No you are just fine ,i miss read your question hold on ill update the answer
    – Bainternet
    Commented Jan 25, 2011 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.