ControlledChaos
10/31/2011 - 11:07 AM

WordPress: Customize Page & Post Metaboxes

WordPress: Customize Page & Post Metaboxes

<?php
$wp_meta_boxes
  [ posttype ]      // dashboard, page, post, ...
  [ column ]        // normal, side
  [ 'core' ]
  [ box_handle ]    // postexcerpt, trackbacksdiv, postcustom, commentstatusdiv,
                    // slugdiv, authordiv, submitdiv, formatdiv, categorydiv, tagsdiv-post_tag
  [ box_attribute ] // id, title, callback, args
<?php
function customize_metaboxes( $post_type, $post ) {
	global $wp_meta_boxes;

	// inspect $wp_meta_boxes
	echo "<pre>";
	var_dump( $wp_meta_boxes );
	echo "</pre>";
	
	// customize ...
}
add_action( 'add_meta_boxes', 'customize_metaboxes', 10, 2 );
<?php
function my_post_abstract_meta_box( $post ) {
?>
  <label class="screen-reader-text" for="excerpt"><?php _e( 'Abstract' ) ?></label>
  <textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt; // textarea_escaped ?></textarea>
  <p>
    This is my custom text.
  </p>
<?php
}

function customize_metaboxes( $post_type, $post ) {
  global $wp_meta_boxes;

  $wp_meta_boxes[ 'post' ][ 'normal' ][ 'core' ][ 'postexcerpt' ][ 'title' ]    = 'Abstract';
  $wp_meta_boxes[ 'post' ][ 'normal' ][ 'core' ][ 'postexcerpt' ][ 'id' ]       = 'postabstract';
  $wp_meta_boxes[ 'post' ][ 'normal' ][ 'core' ][ 'postexcerpt' ][ 'callback' ] = 'my_post_abstract_meta_box';
}
add_action( 'add_meta_boxes', 'customize_metaboxes', 10, 2 );
<?php
/**
 * Display post excerpt form fields.
 *
 * @since 2.6.0
 *
 * @param object $post
 */
function post_excerpt_meta_box($post) {
?>
<label class="screen-reader-text" for="excerpt"><?php _e('Excerpt') ?></label><textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt; // textarea_escaped ?></textarea>
<p><?php _e('Excerpts are optional hand-crafted summaries of your content that can be used in your theme. <a href="http://codex.wordpress.org/Excerpt" target="_blank">Learn more about manual excerpts.</a>'); ?></p>
<?php
}
<?php
$wp_meta_boxes[ 'post' ][ 'normal' ][ 'core' ][ 'post excerpt' ][ 'title' ] = 'Abstract';
$wp_meta_boxes[ 'post' ][ 'normal' ][ 'core' ][ 'post excerpt' ][ 'id' ]    = 'postabstract';