181 posts
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
MCStudios says

Hi i just want to know how do you include scripts in to your wordpress theme, i have seen a few wp themes that include the scripts this way.

<script src="&lt;?php bloginfo('template_url'); ?&gt;/script/myscript.js" type="text/javascript"></script>

and i was looking for some info about this and i found this:

<?php wp_enqueue_script('my_script', WP_CONTENT_URL . 'plugins/my_plugin/my_script.js', array('jquery', 'another_script'), '1.0.0', true);
?>

I’m a little confuse so i just want to know which is the best way to include scripts in to a heme.

Thank’s

31 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 Kingdom
benwebdeveloper says
374 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+3 more
_rohan says

Try and use enqueue. Otherwise if a plugin enqueues say a new version of jQuery, there will be conflicts. Otherwise if you just enqueue jQuery, WP will take care of the dual enqueues.

2578 posts Put a Donk On It
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+10 more
ThemeProvince says

I use an autoload function and include it in the functions.php therefore all my classes I create can be included aswell with just one include statement.

181 posts
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
MCStudios says
I use an autoload function and include it in the functions.php therefore all my classes I create can be included aswell with just one include statement.

Oh, That sounds interesting could you give me an idea of how yo do that?

Thank’s

2578 posts Put a Donk On It
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+10 more
ThemeProvince says
I use an autoload function and include it in the functions.php therefore all my classes I create can be included aswell with just one include statement.

Oh, That sounds interesting could you give me an idea of how yo do that?

Thank’s

This in functions.php

&lt;?php define('WPRoot', TEMPLATEPATH);

// put all your php files in array

$phoenix_includes = array('phoenix_options.php, phoenix_theme_options.php');

include_once('autoload.php');

?&gt;

Create new php doc called autoload.php


<?php // Finds total number in array

$total = count($phoenix_includes);

// Use for loop to iterate & include all your scripts.

for ($i = 0; $i < $total; $i++) {

include(WPRoot."/".$phoenix_includes[$i]); 

}

?>

181 posts
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
MCStudios says
I use an autoload function and include it in the functions.php therefore all my classes I create can be included aswell with just one include statement.

Oh, That sounds interesting could you give me an idea of how yo do that?

Thank’s

This in functions.php

&lt;?php define('WPRoot', TEMPLATEPATH);

// put all your php files in array

$phoenix_includes = array('phoenix_options.php, phoenix_theme_options.php');

include_once('autoload.php');

?&gt;

Create new php doc called autoload.php


<?php // Finds total number in array

$total = count($phoenix_includes);

// Use for loop to iterate & include all your scripts.

for ($i = 0; $i < $total; $i++) {

include(WPRoot."/".$phoenix_includes[$i]); 

}

?>

Hi thank’s for your reply just one last question, ┬┐with this method is it possible to exclude scripts from certain page?

2578 posts Put a Donk On It
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+10 more
ThemeProvince says

Im sure you could with conditional statements. For example:


<?php // Finds total number in array

$total = count($phoenix_includes);

// Use for loop to iterate & include all your scripts.

for ($i = 0; $i < $total; $i++) {

if ($_GET['pageid'] != 3) include(WPRoot."/".$phoenix_includes[$i]);

}

?>

181 posts
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+3 more
MCStudios says
Im sure you could with conditional statements. For example:

Thank’s Phoenix I’m going to try that.

by
by
by
by
by
by