Musíte použít funkci add_meta_box
add_action( 'add_meta_boxes', 'my_custom_meta_box' ) );
function my_custom_meta_box(){
$args = array();
add_meta_box(
'my_metabox_id',
__( 'My Meta Box', 'my_textdomain' ), // Title
'my_callback_function', // Callback function that renders the content of the meta box
'post', // Admin page (or post type) to show the meta box on
'side', // Context where the box is shown on the page
'high', // Priority within that context
$args // Arguments to pass the callback function, if any
);
}
function my_callback_function( $args ){
//The markup for your meta box goes here
}
Vložte níže uvedený kód do souboru function.php
. Níže uvedený kód vytvoří textové pole v typu příspěvku "post". Pouze definování textového pole nebude fungovat, pokud ho chcete uložit, když je příspěvek uložen. zaškrtněte níže url pro uložení hodnoty meta boxu.
add_action( 'add_meta_boxes', 'cd_meta_box_add' );
function cd_meta_box_add(){
add_meta_box( 'my-meta-box-id', 'My First Meta Box', 'cd_meta_box_cb', 'post', 'normal', 'high' );}
function cd_meta_box_cb(){
<label for="my_meta_box_text">Text Label</label>
<input type="text" name="my_meta_box_text" id="my_meta_box_text" />
}
Pro více informací navštivte http://code.tutsplus.com/tutorials/how-to-create-custom-wordpress-writemeta-boxes--wp-20336