在页面中包含脚本template_redirect


Include script in template_redirect page

我正在编写一个插件,必须在此基础上生成一个建议页面,我用template_redirect生成的建议,如下所示:

add_action('template_redirect', 'suggest_page');
function suggest_page() {
  if (!preg_match('/suggest'.php$/', $_SERVER['REQUEST_URI']))
    return;
...
}

我想在这个页面上包含jQuery,我知道可以在</head>之前使用wp_head();然后使用wp_enqueue_script('jquery');但是wp_head();包含很多我不需要的东西。

所以有一种方法可以在不包含WordPress的所有头部内容的情况下将WordPress脚本添加到页面?

来自template_redirect codex,从插件加载模板。 你试过这个吗