【问题标题】:WP - child theme get the theme directoryWP - 子主题获取主题目录
【发布时间】:2018-04-30 08:54:05
【问题描述】:

我在某个与主题相关的 gfx 所在的子目录中有一个图像文件夹。如果我想通过以下方式访问它:

<img src="<?php echo get_template_directory_uri();?>/assets/Logo.svg" />

它正在尝试在父主题目录中查找 /assets。

如何引用子主题目录?

【问题讨论】:

  • 代替get_template_directory_uri使用get_stylesheet_directory_uri函数:
  • @SamvelAleqsanyan 很短,汗水也是准确的正确答案。您应该发布这样的答案,以便我们可以将其标记为已解决,以供将来的提问者和搜索者使用:)

标签: wordpress wordpress-theming


【解决方案1】:

函数get_template_directory_uri总是返回父主题的url。没关系,你在哪里调用它。

要获取您的子主题的网址,您可以使用get_stylesheet_directory_uri()。因此,您的代码将是:

<img src="<?php echo get_stylesheet_directory_uri();?>/assets/Logo.svg" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多