WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

To solve this problem i've used this in my js file:

var location = String(window.location);

//only runs in post.php and post-new.php
if(location.search('post.php') != -1 || location.search('post-new.php') != -1 )


But it's does not seem like i solid solution. Are there any other way?

share|improve this question
up vote 2 down vote accepted

You can use this in your functions.php :

function add_admin_scripts( $hook ) {

    if ( $hook == 'post-new.php' ) {

        wp_enqueue_script(  'myscript', get_bloginfo('template_directory').'/js/myscript.js' );

share|improve this answer
What does, 10,1 in the add_action function means? – Richard Jul 13 '11 at 11:47
10 is the priority; 1 represents the number of variables passed to the callback. – Chip Bennett Jul 13 '11 at 11:57
Note: you could also use the $pagenow global, using the same approach. – Chip Bennett Jul 13 '11 at 12:00

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.