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

1617 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.

3436 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 :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by