Created
April 17, 2012 03:10
-
-
Save BronsonQuick/2403116 to your computer and use it in GitHub Desktop.
Adds an extra metabox on WordPress pages to allow a page to have a tagline
This file contains hidden or 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 debthelpline_add_meta_boxes(){ | |
| // Add the Subheading meta box | |
| add_meta_box( 'debthelpline_banner_subheading', __( 'Banner Subheading', 'debthelpline' ), 'debthelpline_subheading_meta_box', 'page', 'normal', 'high' ); | |
| } | |
| add_action( 'add_meta_boxes', 'debthelpline_add_meta_boxes' ); | |
| function debthelpline_subheading_meta_box( $post ) { | |
| // Use nonce for verification | |
| wp_nonce_field( plugin_basename( __FILE__ ), 'debthelpline_meta_box_nonce' ); | |
| $banner_subheading = get_post_meta( $post->ID, 'debthelpline_banner_subheading', true ); | |
| if( $banner_subheading === false ) | |
| $banner_subheading = ''; | |
| // The actual fields for data entry ?> | |
| <p>The banner subheading appears below the site title on the page's banner image.</p> | |
| <label for="debthelpline_banner_subheading"><?php _e( 'Banner subheading:', 'debthelpline' ); ?></label> | |
| <input type="text" id="debthelpline_banner_subheading" name="debthelpline_banner_subheading" value="<?php echo $banner_subheading; ?>" size="25" /> | |
| <?php | |
| } | |
| /** | |
| * When the post is saved, saves our custom data | |
| */ | |
| function debthelpline_save_meta_box_data( $post_id ) { | |
| if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
| return; | |
| if ( ! wp_verify_nonce( $_POST['debthelpline_meta_box_nonce'], plugin_basename( __FILE__ ) ) ) | |
| return; | |
| if( isset( $_POST['debthelpline_banner_subheading'] ) ) { | |
| update_post_meta( $post_id, 'debthelpline_banner_subheading', $_POST['debthelpline_banner_subheading'] ); | |
| } | |
| } | |
| add_action( 'save_post', 'debthelpline_save_meta_box_data' ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment