php - WordPress - get_template_directory() 返回父主题的 url

标签 php html wordpress include

我正在尝试在 PHP 文件中制作一个简短的 HTML 组件,以便稍后将其包含在站点的不同页面中。

我想使用 get_template_directory() 因为我认为它会返回我实际主题的根 URL。我使用的主题是 child 主题。相反,它似乎返回父级的根目录 URL。

做这一切的正确方法是什么? 我试图将这段 HTML 作为带有一些按钮的组件包含在一些不同的页面中。但我没有将它作为插件包含在内。

我检查了子主题文件夹中的所有内容,据我所知一切正常。

我在 function.php 中有这段代码,从我之前在这里问过的一个问题来看,我认为它没问题。

<?php
add_action('wp_enqueue_scripts', 'adapt_child_enqueue_styles');
function adapt_child_enqueue_styles(){
    wp_dequeue_style('theme-responsive');
    wp_enqueue_style('theme-child-style', get_template_directory_uri().'/style.css');
    wp_enqueue_style('theme-child-responsive', get_stylesheet_directory_uri().'/css/responsive.css');
}
?>

最佳答案

不使用 get_template_directory(),而是使用

get_stylesheet_directory()

这将返回子主题目录而不是父主题目录。在这里阅读更多 https://codex.wordpress.org/Function_Reference/get_stylesheet_directory

关于php - WordPress - get_template_directory() 返回父主题的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42073294/

相关文章:

php - 在 Lumen 中安装 FFMpeg

php - 试图选择 WordPress 生成的 Widget 类?

html - 由于在同一元素的多个指令中使用相同的鼠标事件,指令没有响应

javascript - 导航菜单单击打开和关闭导航元素和内容

jquery - WordPress 网站上的响应图像

javascript - 如何检索通过ajax从 Controller 发送到 View 的数组?

php - 在 PHP 中创建一个文件进度条

html - 用动画显示一个句子

php - 将单个产品页面重定向到 Woocommerce 中的主页

javascript - 如何使用存储在值中的 am/pm 使 PHP 倒计时?