Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking for the action hook corresponding to the click on the "Add page" link. Any idea?

Thanks !

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

If you want to target the admin page that displays the post editor, you'll likely need to hook to two places whether it's for a script or style.

You'd use the top two for scripts and the bottom two for styles.

// Script action for the post new page    
add_action( 'admin_print_scripts-post-new.php', 'example_callback' );

// Script action for the post editting page    
add_action( 'admin_print_scripts-post.php', 'example_callback' );

// Style action for the post new page    
add_action( 'admin_print_styles-post-new.php', 'example_callback' );

// Style action for the post editting page 
add_action( 'admin_print_styles-post.php', 'example_callback' );

If you wanted to target a particular post type, simply global $post_type inside your callback function, like so..

function example_callback() {
    global $post_type;
    // If not the desired post type bail here.
    if( 'your-type' != $post_type )
        return;

    // Else we reach here and do the enqueue / or whatever
}

If you're enqueuing scripts(not styles) specifically there is a hook that runs earlier called admin_enqueue_scripts which passes on the hook as the first arg, so you could also do it like this for scripts..(if you were hooking onto admin_enqueue_scripts instead of the two admin_print_scripts actions above).

function example_callback( $hook ) {
    global $post_type;

    // If not one of the desired pages bail here.
    if( !in_array( $hook, array( 'post-new.php', 'post.php' ) ) )
        return;

    // If not the desired post type bail here.
    if( 'your-type' != $post_type )
        return;

    // Else we reach here and do the enqueue / or whatever
}

These hooks exist exactly for this type of thing, you shouldn't need to fire things as early as admin_init unless your specific use case dictates a requirement to. If you're unsure, chances are you don't need to fire your code that early.

share|improve this answer
    
Thanks I will try to do the trick with that answer ;) –  Kaaviar Feb 24 '11 at 13:07
add comment

you can use the admin_init hook and add you conditionals to page something like

add_action('admin_init','load_my_code');
function load_my_code() {
  global $typenow;
  if (empty($typenow) && !empty($_GET['post'])) {
    $post = get_post($_GET['post']);
    $typenow = $post->post_type;
  }
  if (is_admin() && $typenow=='page') {
    //do your stuff here
  }
}
share|improve this answer
    
Ok thanks that will not do what I need (my question was not precise enough I guess) but it's still usefull –  Kaaviar Feb 24 '11 at 13:06
add comment

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.