admin管理员组文章数量:1317898
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');
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');
3 Answers
Reset to default 135get_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/wp-content/themes/yourtheme
.
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.
Replace
include (TEMPLATEPATH . '/path-to/my-file.php');
with
include dirname( __FILE__ ) . '/path-to/my-file.php';
this should work for most common issues
本文标签: functionsgettemplatedirectoryuri pointing to parent theme not child theme
版权声明:本文标题:functions - get_template_directory_uri pointing to parent theme not child theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742035794a2417284.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论