382 posts
  • Had an item that became a weekly top seller
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Located in New Zealand
+6 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

1665 posts Chris Robinson
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
  • Located in United States
+13 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 5 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.

3439 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Achieved the monthly Community Superstar Award
  • Located in United States
+2 more
organicbee
says

EDIT :I got beat

382 posts
  • Had an item that became a weekly top seller
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Located in New Zealand
+6 more
PixelStores
says

Super fast! KalebAustin code works like a charm.

Cheers :)

by
by
by
by
by
by