To add custom content to the "Write" admin pages (where you write posts, pages or links), WordPress 2.5 introduces a new function set: add_meta_box()

Simple plugin example :
-
<?php
-
/*
-
Plugin Name: Example: Add Meta Box
-
Plugin URI: #
-
Description: Simple example showing how to add a "meta box" in WP 2.5
-
Version: 0.0
-
Author: Ozh
-
Author URI: http://planetozh.com/blog/
-
*/
-
-
// This function tells WP to add a new "meta box"
-
function add_some_box() {
-
add_meta_box(
-
'ozh', // id of the <div> we'll add
-
'My Box', //title
-
'add_something_in_the_box', // callback function that will echo the box content
-
'post' // where to add the box: on "post", "page", or "link" page
-
);
-
}
-
-
// This function echoes the content of our meta box
-
function add_something_in_the_box() {
-
echo "I'm living in a box";
-
}
-
-
// Hook things in, late enough so that add_meta_box() is defined
-
if (is_admin())
-
add_action('admin_menu', 'add_some_box');
-
-
?>
The catch here is to hook the function that add our "meta box" (here: add_some_box()) late enough so that the function it needs, add_meta_box(), has been defined. Hooking on 'admin_menu' is fine.
If you want something compatible with both WordPress 2.3 and 2.5, you will need something like the following:
-
if (function_exists('add_meta_box') {
-
// 2.5 style
-
} else {
-
// 2.3
-
}
Related posts
Shorter URL
Want to share or tweet this post? Please use this short URL: http://ozh.in/gz
Pages: [2] 1 » Show All
pingback on 29/Apr/09 at 2:15 pm # :
[...] breve tutorial con un pezzo di codice per aggiungere tramite plugin del contenuto personalizzato nella pagina di [...]
thought, on 07/Apr/09 at 3:56 pm # :
Giovanni,
Veja se isso ajuda:
Maybe this can help:
http://www.code-styling.de/english/how-to-use-wordpress-metaboxes-at-own-plugins
Câmbio?
Over?
pingback on 24/Dec/08 at 3:03 pm # :
[...] documentação do Wordpress dá pra saber que a (nova) função para criar caixas de opções é a add_meta_box. E se add adiciona, remove exclui e te pergunta três parâmetros. [...]
pingback on 13/Oct/08 at 7:27 pm # :
[...] I found a useful blog post on how to add text fields to the “link management” admin menu in Wordpress: http://planetozh.com/blog/2008/02/wordpress-snippet-add_meta_box/ [...]
commented, on 28/Aug/08 at 4:15 am # :
Next step is how to save a data field :)
replied, on 18/Jun/08 at 3:15 am # :
Hi and thanks for the great reading.
Could answer me, if is there any link or tutorial to insert these meta box's, in a plugin page ?
In my case, I'm writing a domain manager to control a few domains I have, and I want to add these meta box's on the 'Add a Domain' page.
Kind Regards!
thought, on 10/Jun/08 at 9:06 pm # :
Ping » No idea. This code has nothing to do with the editor.