O'Reilly logo

WordPress 2.8 Themes Cookbook by Lee Jordan, Nick Ohrn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding JavaScript files to your theme programmatically

Although you can certainly link to your JavaScript files directly (and in some cases, you may need to, for one reason or another), the preferred method of generating script tags for your theme is to add references programmatically. This allows for the reuse of popular scripts, and ensures that a script is not linked to twice within the same page.

Getting started

You need to have created a WordPress theme that contains at least a style.css file and an index.php file. Inside the template file containing your theme's<head> tag, you need to call the wp_head function. If you have also completed the previous example, open up the header.php file (or whichever file you placed the<script> tag code in) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required