1

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?

3

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' );

    }
}
add_action('admin_enqueue_scripts','add_admin_scripts',10,1);
3
  • What does, 10,1 in the add_action function means?
    – Richard
    Jul 13 '11 at 11:47
  • 1
    10 is the priority; 1 represents the number of variables passed to the callback. Jul 13 '11 at 11:57
  • Note: you could also use the $pagenow global, using the same approach. Jul 13 '11 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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