WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

heelo, I want to use this great hook edit_form_after_title

it was announced on December 1, 2012:
http://make.wordpress.org/core/2012/12/01/more-hooks-on-the-edit-screen/

it curreclty hook for : post-new, post, page-new, page.

how do I make it to work only in edit page/post (only post, page)

thanks all

share|improve this question
up vote 2 down vote accepted

Personally I'd use a different approach, because @Shazzad's solution seems too much global dependent, and @s_ha_dum's needs 2 hooks instead of one.

I'd use get_current_screen function to get a WP_Screen object, then I'd look at its property to run (or not) something after the title:

function do_something_after_title() {
    $scr = get_current_screen();
    if ( ( $scr->base !== 'post' && $scr->base !== 'page' ) || $scr->action === 'add' )
        return;
    echo '<h2>After title only for post or page edit screen</h2>';
}

add_action( 'edit_form_after_title', 'do_something_after_title' );
share|improve this answer
    
Great thanks much – DrMosko Dec 29 '13 at 17:13

Don't know if there was any change during the time that passed from the original question but as of 4.0 you get the post as a parameter to the hook and all that is needed to do is to check the post type. If you wonder what happens when creating a new post the answer is that WordPress generates a dummy post if the post type set to the correct type.

function do_something_after_title( $post ) {
    if( 'post' !== $post->post_type && 'page' !== $post->post_type ) {
        return;
    }

    echo '<h2>After title only for post or page edit screen</h2>';
}
add_action( 'edit_form_after_title', 'do_something_after_title' );
share|improve this answer

Check post type using $typenow and $pagenow global variables.

add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' );
function myprefix_edit_form_after_title()
{
    global $typenow, $pagenow;
    if( in_array($typenow, array('post', 'page') ) && $pagenow == 'post.php' )
    {
        echo '<h2>This is edit_form_after_title!</h2>';
    }
}
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.