Wordpress wp_head() 破坏管理 post

Wordpress wp_head() breaks admin post

我正在尝试使用钩子添加一些与插件关联的 CSS 文件和 JS 文件。

add_action( 'wp_enqueue_scripts', 'vu_add_scripts' );

在我添加之前函数没有触发:

wp_head();

但是,现在每当我尝试添加或编辑 post 时,我都会收到错误消息:

Cannot modify header information - headers already sent by (output started at /Users/warrenday/Sites/Channel4/Admin/wp-includes/general-template.php:2363)

我把 wp_head 放错地方了吗?这是上下文中的全部内容。

function vu_add_scripts(){
$plugin_url = plugin_dir_url( __FILE__ );
    wp_enqueue_script('jquery');
    wp_enqueue_style( 'vu-style', $plugin_url . 'css/style.css' );
    wp_enqueue_script( 'vu-functions', $plugin_url . 'js/functions.js' );
}
add_action( 'wp_enqueue_scripts', 'vu_add_scripts' );

wp_head(); /* Fires the command to add files to head */

wp_head() 仅用于前端,wp_enqueue_scripts.

也是如此

像这样使用admin_enqueue_scripts

function vu_add_scripts( $hook ) {
    $plugin_url = plugin_dir_url( __FILE__ );
    wp_enqueue_script( 'jquery' );
    wp_enqueue_style( 'vu-style', $plugin_url . 'css/style.css' );
    wp_enqueue_script( 'vu-functions', $plugin_url . 'js/functions.js' );
}

add_action( 'admin_enqueue_scripts', 'vu_add_scripts' );

wp_head()函数通常用在您正在使用的主题的header.php文件中。您可以在文件的 HEAD 标签之间找到它。

是否在您主题的 header.php 文件中找到了 wp_head()?从此文件中删除 wp_head() 并将其放入 header.php.

你的其余代码看起来很可靠。