Template Path in WordPress Child Themes

WordPress Child themes are a great Idea to extend the theme a bit without getting your hands dirty with the big deal, but I encountered a problem with my child theme when I wanted to load some of my Javascript files which I kept with in the child theme so that the parent theme remains unchanged and all the development is also done in one directory.

When I tried loading the Javascript using the Template path obtained by

$template_path = get_bloginfo('template_url');

I got the path to the parent theme which of course is wrong in my case as my JS file was in child theme’s folder.

I had to make a custom function to get my child theme’s path. I am copying this function below for people who are facing the same issue. Feel free to copy this function into your functions.php file of your child theme. If you don’t have a functions.php in your child theme then create one


function get_childTheme_url() {
    return dirname( get_bloginfo('stylesheet_url') );
}

After copying this function in functions.php, call this function anywhere to get the path to your child theme; as shown below

$template_path = get_childTheme_url();

Share this article if it was of any help, that might help others as well.

Published by Umair Jabbar

Umair Jabbar is an enthusiast, a Software Engineer / Web Developer who wants web to be simpler for everyone.

Join the Conversation

12 Comments

  1. Thanks for this function! I used this initially but I then I came across get_stylesheet_directory_uri(). This also works :)

  2. Hi Umair,
    You missed your own trick with this. There is no need to make a function.php call at all, and WP hasn’t left this feature out.To call a file from the child theme folder you just use You use stylesheet_url (which is in the the child folder), not template_url (which is the parent theme).Much more elegant! ;-)

  3. get_stylesheet_directory_uri() returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme), not a URI.

    So the code of Umair is very nice if you are requesting any file from your Childtheme.

    Great work Umair

  4. get_stylesheet_directory_uri(); for child theme directory

    and get_stylesheet_uri(); for the stylesheet within the child theme directory.

    So you don’t need to use this function anymore.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.