您的代码正确,but you will not see this <script> tag in your header!
的最后一个参数wp_enqueue_script() 是关于是否在页面底部加载脚本的标志。您将此设置为true, 所以你告诉WordPress创建一个<script> 标记在HTML源的底部,而不是在<head> 要素
此外,如评论中所述,您应该not 正在使用template_redirect 钩住这个。使用add_action( \'wp_enqueue_scripts\', \'add_my_script\' ); 相反