我已经设置了一个儿童主题。是否可以通过FTP在我的服务器上添加一个名为img
的文件夹(最好是在同一个子主题文件夹中),然后从我的页面和帖子链接到该文件夹中的图像?
我尝试使用此路径:
<img src="../wp-content/themes/theme-child/img/placeholder.png"/>
但那没用。
替换为以下代码
<img src="<?php echo get_template_directory_uri(); ?>/img/placeholder.png" />
您需要使用样式表目录。使用子主题,如果您使用模板目录,它将转到父级(请参阅http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri上的说明)。
它应该是<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/placeholder.png" />
是的你可以。然后,您可以通过执行以下操作来访问它... get_template_directory_uri()。'/ img / placeholder.png'
您可以在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">