I would like to add a meta box underneath the title, but before the editor on a page post type in admin. I can add it to a post, but not to a page and I don't understand why.
I've used this to add a new context that will appear under the title.
function buddydev_create_new_metboax_context( $post ) {
do_meta_boxes( null, 'custom-metabox-holder', $post );
}
add_action( 'edit_form_after_title', 'buddydev_create_new_metboax_context' );
This works fab on a post, but if I try to add it to the page post type the metabox displays beneath the text editor, not above it.
Here is my metabox code.
add_action( 'add_meta_boxes', 'at_titles_meta_box' );
function at_titles_meta_box($post){
add_meta_box('at_meta_box', 'Add Title', 'titles_meta_box', array('page'), 'custom-metabox-holder');
}
add_action('save_post', 'at_save_metabox');
function at_save_metabox(){
global $post;
if(isset($_POST["tagline"])){
//UPDATE:
$tagline = $_POST['tagline'];
$sub = $_POST['sub'];
//END OF UPDATE
update_post_meta($post->ID, 'tagline', $tagline);
update_post_meta($post->ID, 'sub', $sub);
}
}
function titles_meta_box($post){
$tagline = get_post_meta($post->ID, 'tagline', true);
$sub = get_post_meta($post->ID, 'sub', true);
?>
<p>
<label for="tagline">Banner Strapline:</label>
<input class="widefat" type="text" name="tagline" id="tagline" value="<?php echo esc_attr( get_post_meta( $post->ID, 'tagline', true ) ); ?>" size="30" />
<br /><br />
<label for="sub">Intro Section Title:</label>
<input class="widefat" type="text" name="sub" id="sub" value="<?php echo esc_attr( get_post_meta( $post->ID, 'sub', true ) ); ?>" size="30" />
</p>
<?php
}
get_current_screen()
to ensure your on the correct post type.