371 posts
  • Has referred 50+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
PixelStores says

Hey,

I want to load a couple of scripts in the wordpress admin area so i used this script:

add_action('init', 'scriptsetup');

function scriptsetup(){
wp_enqueue_script( 'ipt', '/wp-content/themes/mytheme/functions/jquery-1.2.6.js', array( 'jquery' ));
wp_enqueue_script( 'my_awesome_script', '/wp-content/themes/mytheme/functions/form.js', array( 'jquery' ));
}

The php seems to work but it also loads the script all over the site, how do i make it load only in the admin area, even better in the ‘Add New’ post section?

Help appreciated :)

Matt

1610 posts Chris Robinson
  • Located in United States
  • Has sold $500,000+ on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
contempoinc says

This should work:

<?php if ( is_admin() ) {

function scriptsetup(){
wp_enqueue_script( 'ipt', '/wp-content/themes/mytheme/functions/jquery-1.2.6.js', array( 'jquery' ));
wp_enqueue_script( 'my_awesome_script', '/wp-content/themes/mytheme/functions/form.js', array( 'jquery' ));
}

add_action('init', 'scriptsetup');
} ?>
27 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United States
KalebAustin says
add_action('init', 'scriptsetup');

function scriptsetup(){
$svr_uri = $_SERVER['REQUEST_URI'];
     if( is_admin() && strstr($svr_uri, 'post-new.php')){
         wp_enqueue_script( 'ipt', '/wp-content/themes/mytheme/functions/jquery-1.2.6.js', array( 'jquery' ));
         wp_enqueue_script( 'my_awesome_script', '/wp-content/themes/mytheme/functions/form.js', array( 'jquery' ));
     }
}

Try that. Should only add it add-post in admin area, didn’t test it though.

3328 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

EDIT :I got beat

371 posts
  • Has referred 50+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
PixelStores says

Super fast! KalebAustin code works like a charm.

Cheers :)

by
by
by
by
by
by