Quick WordPress Tips – Child theme URL and URI path

A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme, and allows you to change, or add to, the functionality of that parent theme. WordPress Child themes are a great idea to extend the theme a bit without getting your hands dirty with the big deal. For this reason, child themes are the recommended way of making modifications to a theme.
I encountered a problem with my child theme when I wanted to load some of my JavaScript files for the theme’s option 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.

Here is the solution:
Use the URI

<!--?php get_stylesheet_directory_uri(); ?-->

Output the URI

<!--?php echo get_stylesheet_directory_uri(); ?-->

With get_stylesheet_directory_uri(), I can load addition JavaScript files in my WordPress child theme

if (is_admin()){ //load scripts for admin page
	wp_enqueue_style('admin-style', get_stylesheet_directory_uri() . '/admin/option.css', false);
	wp_enqueue_script('admin-scripts', get_stylesheet_directory_uri() . '/admin/script.js', array('jquery'), '1.0', false);

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

The author avatar

NARGA Editorial

Nguyễn Đình Quân is one of NARGA Editorials. He's 35 years old self-taught web developer and freelance blogger from Hải Phòng, Việt Nam. He is the founder of NARGA.NET where he's blogging everything about web development, graphic and WordPress related. Do you interesting with our website to post your own post or place your advertise? Contact us now!

You may also like...

Leave a Reply

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