366 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 4-5 years
  • New Zealand
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
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

1579 posts Chris Robinson
  • United States
  • Sold between 250 000 and 1 000 000 dollars
  • Elite Author
  • Has been a member for 5-6 years
  • Author had a File in an Envato Bundle
  • Referred between 500 and 999 users
  • Author had a Free File of the Month
+5 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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • 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.

3192 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

EDIT :I got beat

366 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 4-5 years
  • New Zealand
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
PixelStores says

Super fast! KalebAustin code works like a charm.

Cheers :)

by
by
by
by
by
by