0

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 :)

1 Answer 1

1

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.

5
  • Thanks for the answer! But for some reason it has the same flaw as the previous code, not effecting edit page.
    – any_h
    Commented Sep 16, 2011 at 22:03
  • is the script loaded? can you see it in the source?
    – Bainternet
    Commented Sep 16, 2011 at 22:16
  • Not seeing the script anywhere.
    – any_h
    Commented Sep 16, 2011 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
    Commented Sep 16, 2011 at 23:23
  • This is what I've been using pastie.org/2545593
    – any_h
    Commented Sep 16, 2011 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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