无插件实现禁止某些不必要的功能

By | January 5, 2013

wordpress的功能是非常的丰富的,有些时候这些丰富的功能反倒使得我们的网站占用数据库空间和存在一些不安全因素。所以,麦子比较喜欢把必须要的功能都取消掉。取消这些功能是根据自己的需要设置的,如果你认为有用你就留着,如果你认为没用,就取消。这些取消的方式不会损坏我们当前的系统架构,仅仅是在我们的当前模板的functions.php文件中设置。

<?php
//禁用l10n.js
wp_deregister_script(‘l10n’);
//彻底移除管理员工具条(By 荒野无灯)
add_filter(‘show_admin_bar’,’__return_false’);
//禁用自动保存草稿
wp_deregister_script(‘autosave’);
//禁用修改历史记录
remove_action(‘pre_post_update’,’wp_save_post_revision’);
//禁止在head泄露wordpress版本号
remove_action(‘wp_head’,’wp_generator’);
//移除head中的rel=”EditURI”
remove_action(‘wp_head’,’rsd_link’);
//移除head中的rel=”wlwmanifest”
remove_action(‘wp_head’,’wlwmanifest_link’);
//禁止半角符号自动变全角
foreach(array(‘comment_text’,’the_content’,’the_excerpt’,’the_title’) as $xx)
remove_filter($xx,’wptexturize’);
//禁止自动给文章段落添加<p>标签
remove_filter(‘the_content’,’wpautop’);
remove_filter(‘the_excerpt’,’wpautop’);
//禁止自动把’Wordpress’之类的变成’WordPress’
remove_filter(‘comment_text’,’capital_P_dangit’,31);
remove_filter(‘the_content’,’capital_P_dangit’,11);
remove_filter(‘the_title’,’capital_P_dangit’,11);
//评论跳转链接添加nofollow
function nofollow_compopup_link(){
return’ rel=”nofollow”‘;
}
add_filter(‘comments_popup_link_attributes’,’nofollow_compopup_link’);
/*回复某人链接添加nofollow
这个理应是原生的, 可是在wp某次改版后被改动了,
现在是仅当开启注册回复时才有nofollow,否则需要自己手动了*/
function nofollow_comreply_link($link){
return str_replace(‘<a’,'<a rel=”nofollow”‘,$link);
}
get_option(‘comment_registration’)||
add_filter(‘comment_reply_link’,’nofollow_comreply_link’);
?>

以上的代码根据我们自身的需要设置,也不要什么都禁止掉。有些还是可以需要的。

Leave a Reply