Adding Scripts - WordPress Child Theme Gotcha

While converting a heavily customized premium theme into a proper WordPress child theme I came across a gotcha in WordPress.

If you look at the WordPress Codex information on adding scripts to your theme all of the code samples tell you to find the script by using get_bloginfo('template_directory');

Unfortunately if you're dealing with a child theme this returns the location of the parent them not the location of the child theme. That means that your file is returning a 404 (it's not being found).

Again, unfortunately the WordPress Child theme information does not include a remedy for this so after a bit of typing (calling print_r on variations of bloginfo();) I found that bloginfo('stylesheet_url'); returns the location of your child theme properly.

So the code to include your custom JS script would look like:

wp_register_script('custom_script', get_bloginfo('stylesheet_url').'/path/to/custom.js', array('name_of_script_dependencies'), '1.0');