admin管理员组文章数量:1414604
I am using a child theme but it does not display any images. I am reading a book which suggests the following: "There is a difference in calling images from parent themes and child themes:
for parent Theme:
<?php echo get template_directory_uri(); ?>
for child Theme:
<?php bloginfo('stylesheet_directory'); ?>
Unfortunately the book doesn't say where the relevant code should be inserted.
Any ideas please.
I am using a child theme but it does not display any images. I am reading a book which suggests the following: "There is a difference in calling images from parent themes and child themes:
for parent Theme:
<?php echo get template_directory_uri(); ?>
for child Theme:
<?php bloginfo('stylesheet_directory'); ?>
Unfortunately the book doesn't say where the relevant code should be inserted.
Any ideas please.
- 1 Hi Sebastian, welcome to WPSE. Thanks for taking the tour :) You might need to provide us with some more information to help you solve this. As it stands your question is pretty broad and might be closed. Is there anything you can add by editing your question? For example, how are you calling the images at the moment? Are you seeing any errors? – Tim Malone Commented May 10, 2016 at 21:19
2 Answers
Reset to default 4You could try the following if you have a child theme and trying to reference your images from that file location, onto your custom .php files...
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/your-custom-image.jpg" />
Just make sure in your child theme location, you really have a child folder structure of...
assets -> images
Images that are uploaded through WordPress are saved to /wp-content/uploads/
independent of your theme or child theme, and commonly accessed through helper functions (e.g. the_post_thumbnail()
) that will output HTML, including the image path(s). Therefore I'm ruling out that this is what you are trying to do.
Instead I'm assuming you are trying to load (static) assets from e.g. /wp-content/(child-)theme/assets/images/
. This can be done anywhere in your theme, e.g. in a template; let's say home.php
. I found the description on https://codex.wordpress/Function_Reference/get_stylesheet_directory_uri most helpful.
In a template, you can do the following:
Child theme syntax:
<body>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/image.png" />
</body>
In the event a child theme is being used, this function will return the child's theme directory URI. Use
get_template_directory_uri()
to avoid being overridden by a child theme.
for a parent theme, the syntax would be:
<body>
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/image.png" />
</body>
Similar references are often made when enqueuing scripts or stylesheets in functions.php
:
/*
* Enqueue a script with the correct path.
*/
function wpdocs_scripts_method() {
wp_enqueue_script(
'custom_script',
get_template_directory_uri() . '/js/custom_script.js',
array('jquery')
);
}
Last code example was contributed by bhlarsen on https://developer.wordpress/reference/functions/get_template_directory_uri/
本文标签: Wordpress Child Theme Calling Images
版权声明:本文标题:Wordpress Child Theme Calling Images 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745193874a2647042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论