I created a custom post type and i want to display some text on the editor page below the title and above the text editor. How can i do this?
I tried using add_meta_box, but i wasn't able to move it above the editor.
The best way would be using JavaScript to inject the element.
Here's the gist of the markup for that page:
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
<div id="titlediv">
... other stuff ...
</div>
<div id="postdivrich" class="postarea">
... other stuff ...
</div>
</div>
</div>
</div>
The titlediv
is the title. The postdivrich
is the content editor. You want to insert something between them. Using jQuery, this is pretty easy. Just tell it to insert your markup after the titlediv
:
jQuery(function($) {
var text_to_insert = "This is some text you'll throw between the title and editor.";
$('<p>' + text_to_insert + '</p>').insertAfter('#titlediv')
});
Here is the result of using that exact code on my own site:
new hooks for the add/edit post screen: edit_form_after_title
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' );
function myprefix_edit_form_after_title() {
echo '<h2>This is edit_form_after_title!</h2>';
}
We add a Custom Meta Box and do our thing inside it.
There are some hooks that are not Meta Boxes and we can use to insert content into that admin page:
add_action( 'edit_form_top', function( $post )
{
echo '<h1 style="color:red">edit_form_top</h1>';
});
add_action( 'edit_form_after_title', function( $post )
{
echo '<h1 style="color:red">edit_form_after_title</h1>';
});
add_action( 'edit_form_after_editor', function( $post )
{
echo '<h1 style="color:red">edit_form_after_editor</h1>';
});
add_action( 'edit_page_form', function( $post )
{
// edit_page_form is ONLY for pages, the other is for the rest of post types
echo '<h1 style="color:red">edit_page_form/edit_form_advanced</h1>';
});
add_action( 'dbx_post_sidebar', function( $post )
{
echo '<h1 style="color:red">dbx_post_sidebar</h1>';
});
To anyone with this problem, check this post: More hooks on the edit screen It allows to insert custom content by new native Wordpress hook, which is by far more stable sollution.
Use as described in @DrMosko's answer.