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

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

Here you go:

function load_my_script() {
    global $pagenow, $typenow;
    if (is_admin() && $pagenow=='post-new.php' OR $pagenow=='post.php' && $typenow=='Custom_post_type_name') {

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

Your Answer


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.