在wordpress儿童主题中创建一个图像文件夹

问题描述 投票:1回答:5

我已经设置了一个儿童主题。是否可以通过FTP在我的服务器上添加一个名为img的文件夹(最好是在同一个子主题文件夹中),然后从我的页面和帖子链接到该文件夹​​中的图像?

我尝试使用此路径:

<img src="../wp-content/themes/theme-child/img/placeholder.png"/>

但那没用。

wordpress
5个回答
2
投票

替换为以下代码

<img src="<?php echo get_template_directory_uri(); ?>/img/placeholder.png" />

7
投票

您需要使用样式表目录。使用子主题,如果您使用模板目录,它将转到父级(请参阅http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri上的说明)。

它应该是<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/placeholder.png" />


0
投票

是的你可以。然后,您可以通过执行以下操作来访问它... get_template_directory_uri()。'/ img / placeholder.png'


0
投票

经过测试的脚本

src="<?php echo get_stylesheet_directory_uri(); ?>/images/welcome.png" alt="">

见参考link


0
投票

您可以在Child Theme目录中创建img文件夹,并可以通过与core / parent主题目录引用get_template_directory_uri()相同的方式访问它。这将返回子主题目录URI,因为您在子主题中引用它。

<img src="<?php echo get_template_directory_uri(); ?>/img/childthemeimage.png" alt="Child Theme Image">
© www.soinside.com 2019 - 2024. All rights reserved.