WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 5 down vote accepted

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:

Inserting text before the editor.

share|improve this answer
    
Thanks, its fine for me, but you have to admit, an action to insert some content or something else like that would be better:) – passatgt Aug 8 '12 at 19:36
    
Might need to add a patch for that :-) Thanks. – EAMann Aug 8 '12 at 19:55

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>';
}
share|improve this answer

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.

Mentioned hooks

  • edit_form_after_title
  • edit_form_after_editor
  • edit_form_advanced

Use as described in @DrMosko's answer.

share|improve this answer

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>';
});

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.