0

在 wordpress 主题中排队 javascript 文件时,使用 wp_footer 作为钩子有什么缺点吗?我有大约 5 个文件要排入页脚,但是将页脚的 wp_enqueue_script 属性设置为 true 并没有做任何事情。

我的页脚文件中有 wp_footer() ,当我将操作更改为:

add_action('wp_footer', 'extra_scripts');

脚本在页脚中加载良好。这仅用于演示,而不仅仅是前端显示。以这种方式在页脚中加载脚本有什么问题吗?

4

1 回答 1

0

你应该在页脚中加入你可以做的事情。要强制使用:

// force all JS to the footer
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);

这样你就可以使用默认的了wp_enqueue_scripts
请记住,有些脚本需要<head>像二十一/二十一的HTML5 脚本一样

于 2012-07-08T09:41:15.320 回答