王顺义 發表於 2023-8-28 00:00:00

wordpress优化头部 去掉版权等信息 wordpress去掉generator

<p>
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>wordpress在默认情况下,头部会出现很多平时用不到的html代码,比如: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
&lt;link rel="alternate" type="application/rss+xml" /&gt;
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>上面的标签中,比如generator,将会暴露你的博客程序用的是哪个版本,这个信息泄漏有时会对博客的安全产生一定的影响。同时,也并不需要用这么些标签。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>去掉一些不用的标签,网上有方法说主题目录下的 functions.php里增加以下代码: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function wpbeginner_remove_version() { <br>
return &amp;rdquo;; <br>
} <br>
add_filter('the_generator', 'wpbeginner_remove_version');//wordpress的版本号 <br>
remove_action('wp_head', 'feed_links', 2);// 包含文章和评论的feed。 <br>
remove_action('wp_head', 'index_rel_link');//当前文章的索引。 <br>
remove_action('wp_head', 'wlwmanifest_link'); // 外部编辑器如windows live writer必须。 <br>
remove_action('wp_head', 'feed_links_extra', 3);// 额外的feed,例如category, tag页。 <br>
remove_action('wp_head', 'start_post_rel_link', 10, 0);// 开始篇 <br>
remove_action('wp_head', 'parent_post_rel_link', 10, 0);// 父篇 <br>
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // 上、下篇. </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>测试了下,可以去掉wordpress的generator,有些代码还是去不掉,但还有另个一个更直接的方法。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>就是在wodpress目录下修改wp-includes目录下的default-filters.php,大概在180多行: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
//add_action( 'wp_head', 'feed_links', 2 ); <br>
//add_action( 'wp_head', 'feed_links_extra', 3 ); <br>
//add_action( 'wp_head', 'rsd_link' ); <br>
//add_action( 'wp_head', 'wlwmanifest_link' ); <br>
//add_action( 'wp_head', 'index_rel_link' ); <br>
//add_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); <br>
//add_action( 'wp_head', 'start_post_rel_link', 10, 0 ); <br>
//add_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); <br>
add_action( 'wp_head', 'locale_stylesheet' ); <br>
add_action( 'publish_future_post', 'check_and_publish_future_post', 10, 1 ); <br>
add_action( 'wp_head', 'noindex', 1 ); <br>
add_action( 'wp_head', 'wp_print_styles', 8 ); <br>
add_action( 'wp_head', 'wp_print_head_scripts', 9 ); <br>
//add_action( 'wp_head', 'wp_generator' ); <br>
//add_action( 'wp_head', 'rel_canonical' ); <br>
add_action( 'wp_footer', 'wp_print_footer_scripts' ); <br>
//add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); <br>
add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>不需要的直接//注释掉就行了。一般看下就应该明白是什么意思的。这样可以保证html头部不再有其它的代码了。去掉了wordpress的generator标签。</span></p>
頁: [1]
查看完整版本: wordpress优化头部 去掉版权等信息 wordpress去掉generator