181 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Mexico
  • Has been a member for 4-5 years
  • Bought between 100 and 499 items
  • Referred between 10 and 49 users
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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • United Kingdom
benwebdeveloper says
374 posts
  • Bought between 10 and 49 items
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
_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.

2566 posts Put a Donk On It
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Exclusive Author
  • Attended a Community Meetup
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 200 and 499 users
+5 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
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Mexico
  • Has been a member for 4-5 years
  • Bought between 100 and 499 items
  • Referred between 10 and 49 users
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

2566 posts Put a Donk On It
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Exclusive Author
  • Attended a Community Meetup
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 200 and 499 users
+5 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
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Mexico
  • Has been a member for 4-5 years
  • Bought between 100 and 499 items
  • Referred between 10 and 49 users
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?

2566 posts Put a Donk On It
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Exclusive Author
  • Attended a Community Meetup
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 200 and 499 users
+5 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
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Mexico
  • Has been a member for 4-5 years
  • Bought between 100 and 499 items
  • Referred between 10 and 49 users
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