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 would like to add extra js file to a backend when editing or creating a custom post type.

I found pretty good answer to it but it has a flaw, it wont work when editing the custom post type, only on create and archive view.

Thank you :)

share|improve this question
add comment

1 Answer

Here you go:

add_action("admin_print_scripts","load_my_script");
function load_my_script() {
    global $pagenow, $typenow;
    if (is_admin() && $pagenow=='post-new.php' OR $pagenow=='post.php' && $typenow=='Custom_post_type_name') {
        wp_enqueue_script('jquery');
    }
}

just change Custom_post_type_name to the actual name of your custom post type and enqueue your script.

share|improve this answer
    
Thanks for the answer! But for some reason it has the same flaw as the previous code, not effecting edit page. –  any_h Sep 16 '11 at 22:03
    
is the script loaded? can you see it in the source? –  Bainternet Sep 16 '11 at 22:16
    
Not seeing the script anywhere. –  any_h Sep 16 '11 at 22:20
    
well then you must be doing something wrong, I use this same snippet in my latest plugin en.bainternet.info/2011/simple-gist-embed which works just fine. paste your code and i'll take a look –  Bainternet Sep 16 '11 at 23:23
    
This is what I've been using pastie.org/2545593 –  any_h Sep 16 '11 at 23:40
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.