gpt4 book ai didi

WordPress wp_head - 如何将新的脚本文件添加到顶部?

转载 作者:行者123 更新时间:2023-12-03 07:22:02 24 4
gpt4 key购买 nike

如何将脚本文件添加到 wp_head 的最顶部?

根据本指南,使用下面的代码将始终将我的新脚本文件添加到最底部:

add_action('wp_head','hook_javascript');

function hook_javascript() {

$output="<script> alert('Page is loading...'); </script>";

echo $output;
}

有什么想法可以将我的新脚本文件移动到顶部吗?

最佳答案

使用 add_action()$priority 参数功能。

add_action( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )

$priority
(int) (Optional) Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
Default value: 10

因此,选择一个非常低的数字,只要没有其他插件/主题使用更低的数字,您的行就会添加到顶部。

add_action('wp_head','hook_javascript', -1000);

关于WordPress wp_head - 如何将新的脚本文件添加到顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35684159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com