get_template_directory_uri pointing to parent theme not child theme
The problem I am having is that the get_template_directory_uri is pointing to the parent theme like
site/wp-content/themes/twentythirteen/myGallery/gallery_functions_include.php
but I want it to point to my child theme which should be
site/wp-content/themes/child-twentythirteen/myGallery/gallery_functions_include.php
what I am using is
include (TEMPLATEPATH . '/myGallery/gallery_functions_include.php');
Solutions
You should move your custom templates, those that are not controlled by the active theme, to a child folder.
Keep the theme separate from all customized files this way the theme can be updated without losing your custom work.
Your out-of-the-box theme lives here ------------------------------------ \\Site\wp-content\themes\some_theme
Your child theme lives here --------------------------- \\Site\wp-content\themes\some_theme-child
Your custom styles and templates and all your includes (things like custom javascript , images that are not saved to WP, custom fonts, json data files, and any plugins that you might enqueue) should be moved to child folder OUTSIDE of theme.
\themes\some_theme \themes\some_theme-child\ (all your custom php template files here) \themes\some_theme-child\images \themes\some_theme-child\includes \themes\some_theme-child\languages \themes\some_theme-child\json \themes\some_theme-child\style
For your custom style pages ( not the theme's overridden style.css ) enqueue with wp_enqueue_style( 'some-css', get_stylesheet_directory() . '/style/some.css' , false, '0.0.1', 'all');
Use get_stylesheet_directory_uri() with your xhr calls, etc.
get_template_directory_uri()
will always return the URI of the
current parent
theme.
To get the child theme URI instead, you need to use
get_stylesheet_directory_uri()
.
You can find these in the documentation, along with a list of other useful functions for getting various theme directory locations.
If you prefer to use a constant, then
TEMPLATEPATH
is akin to calling
get_template_directory()
(i.e. the parent theme), and
STYLESHEETPATH
is akin to calling
get_stylesheet_directory()
(i.e. the child theme).
These constants are set by WordPress core in
wp-includes/default-constants.php
and basically look like this:
define('TEMPLATEPATH', get_template_directory());
...
define('STYLESHEETPATH', get_stylesheet_directory());
If there is no child theme, then both the 'template' and 'stylesheet' functions will return the parent theme location.
Note the difference between these functions and the functions ending in
_uri
- these will return the absolute server path (eg.
/home/example/public_html/wp-content/yourtheme
), whereas the
_uri
functions will return the public address (aka URL) - eg.
http://example.com/wp-content/themes/yourtheme
.
Replace
include (TEMPLATEPATH . '/path-to/my-file.php');
with
include dirname( __FILE__ ) . '/path-to/my-file.php';
this should work for most common issues