Correctly using wp_head()

时间:2014-02-01 作者:Paul Nelson Baker

我正在研究我的第一个主题,我发现我不得不打电话wp_header() 之前</head>.

我的标题。php文件包含以下内容:

<!DOCTYPE html>
<html>
    <head>
        <title><?php bloginfo(\'name\'); ?> | <?php the_title(); ?></title>
        <meta content=\'text/html;charset=utf-8\' http-equiv=\'Content-Type\'>
        <meta content=\'utf-8\' http-equiv=\'encoding\'>
        <meta name=\'viewport\' content=\'width=device-width\'>
        <link rel=\'stylesheet\' type=\'text/css\' href=\'<?php bloginfo(\'stylesheet_url\'); ?>\'>
        <link rel=\'stylesheet\' type=\'text/css\' href=\'<?php bloginfo(\'template_directory\'); ?>/side-nav.css\'>
        <?php wp_head(); ?>
    </head>
然而,自从我开始调用这个方法以来,我的标题现在有一些额外的绒毛,这会打乱我的布局。

<!DOCTYPE html>
<html>
    <head>
        <title>Faux Pas Improv Comedy | Hello world!</title>
        <meta content=\'text/html;charset=utf-8\' http-equiv=\'Content-Type\'>
        <meta content=\'utf-8\' http-equiv=\'encoding\'>
        <meta name=\'viewport\' content=\'width=device-width\'>
        <link rel=\'stylesheet\' type=\'text/css\' href=\'http://localhost/htdocs/wp-content/themes/super-plain/style.css\'>
        <link rel=\'stylesheet\' type=\'text/css\' href=\'http://localhost/htdocs/wp-content/themes/super-plain/side-nav.css\'>
        <link rel=\'stylesheet\' id=\'open-sans-css\'  href=\'//fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&#038;subset=latin%2Clatin-ext&#038;ver=3.8.1\' type=\'text/css\' media=\'all\' />
        <link rel=\'stylesheet\' id=\'dashicons-css\'  href=\'http://localhost/htdocs/wp-includes/css/dashicons.min.css?ver=3.8.1\' type=\'text/css\' media=\'all\' />
        <link rel=\'stylesheet\' id=\'admin-bar-css\'  href=\'http://localhost/htdocs/wp-includes/css/admin-bar.min.css?ver=3.8.1\' type=\'text/css\' media=\'all\' />
        <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost/htdocs/xmlrpc.php?rsd" />
        <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://localhost/htdocs/wp-includes/wlwmanifest.xml" /> 
        <meta name="generator" content="WordPress 3.8.1" />
        <style type="text/css" media="print">#wpadminbar { display:none; }</style>
        <style type="text/css" media="screen">
    html { margin-top: 32px !important; }
    * html body { margin-top: 32px !important; }
    @media screen and ( max-width: 782px ) {
        html { margin-top: 46px !important; }
        * html body { margin-top: 46px !important; }
    }
</style>
    </head>
我的问题是,如何从wp\\U头添加的额外内容中删除我不需要的内容;还有什么是我绝对不能从wp\\u头中删除的?

2 个回复
最合适的回答,由SO网友:Otto 整理而成

“额外的东西”是给管理栏的。如果它弄乱了你的布局,那么你应该纠正布局,使它不会弄乱。

SO网友:Vital Lokossou

在此处获取答案http://davidwalsh.name/remove-wordpress-admin-bar-css. 只需将此函数添加到函数中即可。php

add_action(\'get_header\', \'remove_admin_login_header\');
function remove_admin_login_header() {
    remove_action(\'wp_head\', \'_admin_bar_bump_cb\');
}

结束

相关推荐