Wordpress wp_head()打破了管理员帖子

时间:2015-02-12 11:43:40

标签: wordpress

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

add_action( 'wp_enqueue_scripts', 'vu_add_scripts' );

函数没有激发,直到我添加:

wp_head();

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

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 */

2 个答案:

答案 0 :(得分:1)

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' );

答案 1 :(得分:0)

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

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

其余代码似乎很可靠。