【问题标题】:Parent (functions.php) executes but actions doesn't seem to work父(functions.php)执行但操作似乎不起作用
【发布时间】:2021-07-19 04:39:29
【问题描述】:

我正在阅读这个 WordPress 主题流程图。

我已经在我的 wordpress 中设置了一个基本的父/子主题。

子主题(functions.php)

<?php 

echo "child theme";

父主题(functions.php)

<?php 

echo "top";

function coffee_enqueue_styles() {
    echo "parent theme";
}

add_action('wp_enqueue_scripts', 'coffee_enqueue_styles');

echo "bottom";

所以在我激活我的子主题后,它会加载并执行它的 functions.php 文件并打印child theme。然后 WordPress 检查这个主题是否有父主题,它执行它的 functions.php 文件,在我的情况下它会打印 topbottom 但由于某种原因它不执行 @ 987654330@ 钩住我正在打印的地方enqueued from parent

这是我得到的输出。

我错过了什么吗?请指导我。谢谢你。

更新

我将我的操作更改为init,它在bottom 的末尾打印parent theme。所以我的动作挂钩工作正常。

拜托,你能告诉我为什么wp_enqueue_scripts钩子没有执行或者背后有什么命令吗?

【问题讨论】:

    标签: php wordpress frontend wordpress-theming wp-enqueue-scripts


    【解决方案1】:

    检查核心文件后。我在wp-includes/default-filters.php 中发现了这一点。 WordPress 正在绑定 wp_enqueue_scriptswp_head

    这意味着wp_enqueue_scripts 钩子只有在wp_head 钩子执行时才会起作用。

    所以,我在模板中缺少wp_head 函数。

    【讨论】:

      猜你喜欢
      • 2016-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-14
      • 1970-01-01
      • 2014-01-08
      相关资源
      最近更新 更多