I am displaying a div in the Edit Post screen using add_meta_box(). This function provides very limited positioning options via “priority” and “context” params and these are not sufficient for my needs.

I need to be able to display the div below the Permalink but above the Insert Media button on Edit Post, specifically below the div “titlediv”, above the div “postdivrich”.

How else can I position the meta box on the post edit screen? Can this be done through jQuery?

Here’s a partially working solution:

function admin_init(){
  add_meta_box("wd_meta", "WD Meta", "wd_meta", "post", "normal", "high");
}
add_action("admin_init", "admin_init");

function wd_meta() {
    global $post;
    $custom = get_post_custom($post->ID);
?>
<div id="wdMeta">
<p>Display a message here.</p>
</div> 

<script>
$('#wd_meta').insertAfter('#titlediv'); 
</script>
<?php } ?>

The meta box is displaying on the page correctly, but the javascript is not positioning it correctly, even though it appears to work in demo:

http://jsfiddle.net/kFTc5/11/

1
1

You cannot use a real metabox to do that, hook into edit_form_after_title instead.

enter image description here

Here is a simple example:

add_action( 'edit_form_after_title', 'wpse_87478_pseudo_metabox' );
add_action( 'save_post', 'wpse_87478_save_metabox' );

function wpse_87478_pseudo_metabox()
{
    global $post;
    $key = '_wpse_87478';

    if ( empty ( $post ) || 'post' !== get_post_type( $GLOBALS['post'] ) )
        return;

    if ( ! $content = get_post_meta( $post->ID, $key, TRUE ) )
        $content="";

    printf(
        '<p><label for="%1$s_id">Enter some text
        <input type="text" name="%1$s" id="%1$s_id" value="%2$s" class="all-options" />
        </label></p>',
        $key,
        esc_attr( $content )
    );
}

function wpse_87478_save_metabox( $post_id )
{
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
        return;

    if ( ! current_user_can( 'edit_post', $post_id ) )
        return;

    $key = '_wpse_87478';

    if ( isset ( $_POST[ $key ] ) )
        return update_post_meta( $post_id, $key, $_POST[ $key ] );

    delete_post_meta( $post_id, $key );
}

Leave a Reply

Your email address will not be published. Required fields are marked *