首页 开发指南

2014-05-12 村上桐树2,053

有关wp_head()函数的一些说明

今天在用一个插件的时候发现,不管在主题里怎么写都不起作用,后来查了下,原来是我把wp_head()这个函数给去年的缘故,之所以去掉,是因为这个函数的输出实在是太繁琐了。
不得以只好加上,加上后却发现了页面顶部加了一段CSS。

?<style type="text/css" media="print">#wpadminbar { display:none; }</style>
<style type="text/css">
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>

有人说是没在前加wp_footer(),但是我加了,没用。
然后只能找老外了:

After updating my wordpress it started cause some unusual body spacing. When I view page source I see some unusual coding, trouble is I dont know which file it’s located in to delete it:

<style type=”text/css” media=”print”>#wpadminbar { display:none; }</style>
<style type=”text/css”>
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>

There’s the css that shouldn’t be in the index but I dont know how it got there or how to get rid of it. It’s magically appeared after the update, any suggestions?

———————————————————————————

Try adding this to your theme’s functions.php. This fixed the issue on my site:
function my_function_admin_bar(){ return false; }add_filter( ‘show_admin_bar’ , ‘my_function_admin_bar’);

———————————————————————————

First up, no one ever edit core, please 😉 Also posting in resolved topics makes it hard for us to know you need help. We assume if it’s resolved, you’re done.

If your site is munging the admin bar layout, check that you have BOTH wp_head() and wp_footer() in your theme. You need both 😀

If that doesn’t help, you can put this in your functions.php:
function my_admin_css() { if ( is_user_logged_in() ) { ?> <style type=”text/css”>[PUT YOUR CSS FOR LOGGED IN USERS HERE!] </style> <?php }}add_action(‘wp_head’, ‘my_admin_css’);

If you want to change it for non-logged in users, it’s !is_user_logged_in

最后附上完整的wp_head()清理函数:

<?php
//remove_action( ‘wp_head’, ‘wp_enqueue_scripts’, 1 );
remove_action( ‘wp_head’, ‘feed_links’, 2 );
remove_action( ‘wp_head’, ‘feed_links_extra’, 3 );
remove_action( ‘wp_head’, ‘rsd_link’ );
remove_action( ‘wp_head’, ‘wlwmanifest_link’ );
remove_action( ‘wp_head’, ‘index_rel_link’ );
remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 );
remove_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 );
remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 );
//remove_action( ‘wp_head’, ‘locale_stylesheet’ );
remove_action( ‘publish_future_post’, ‘check_and_publish_future_post’, 10, 1 );
//remove_action( ‘wp_head’, ‘noindex’, 1 );
//remove_action( ‘wp_head’, ‘wp_print_styles’, 8 );
//remove_action( ‘wp_head’, ‘wp_print_head_scripts’, 9 );
remove_action( ‘wp_head’, ‘wp_generator’ );
//remove_action( ‘wp_head’, ‘rel_canonical’ );
remove_action( ‘wp_footer’, ‘wp_print_footer_scripts’ );
remove_action( ‘wp_head’, ‘wp_shortlink_wp_head’, 10, 0 );
remove_action( ‘template_redirect’, ‘wp_shortlink_header’, 11, 0 );

add_action(‘widgets_init’, ‘my_remove_recent_comments_style’);
function my_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action(‘wp_head’, array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], ‘recent_comments_style’));
}
?>

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

会员评论:(0)

声明:本站所有主题/文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除,谢谢!
©www.sbmzenith.com 2013-2020 All Rights Reserved.
豫ICP备15009393号