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.

Get more stuff like this

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

Scroll To Top

Pin It on Pinterest

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.