Created
September 23, 2018 16:42
-
-
Save ControlledChaos/776042aa635960e5841df3cf6ac3d668 to your computer and use it in GitHub Desktop.
WordPress: Customize Page & Post Metaboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$wp_meta_boxes[ 'post' ][ 'normal' ][ 'core' ][ 'post excerpt' ][ 'title' ] = 'Abstract'; | |
$wp_meta_boxes[ 'post' ][ 'normal' ][ 'core' ][ 'post excerpt' ][ 'id' ] = 'postabstract'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment