移除wordpress版本信息 删除无用信息
wordpress页面头部有很多无用的信息,像wordpress版本信息、feed等,如何把它们删除或不让它们先是出来呢?
将下面的代码加入到当前主题的functions.php,可以适当酌情保留
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?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' )); } ?> |
还有一些版本可供借鉴
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | remove_action( 'wp_head' , 'wp_enqueue_scripts' , 1 ); //Javascript的调用 remove_action( 'wp_head' , 'feed_links' , 2 ); //移除feed remove_action( 'wp_head' , 'feed_links_extra' , 3 ); //移除feed 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 ); //载入css remove_action( 'wp_head' , 'wp_print_head_scripts' , 9 ); remove_action( 'wp_head' , 'wp_generator' ); //移除WordPress版本 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' )); } |
1 | remove_action( 'wp_head' , '_wp_render_title_tag' , 1 ); //移除标题 |
1 2 | remove_action( 'wp_head' , 'rest_output_link_wp_head' , 10 ); //禁用REST API remove_action( 'wp_head' , 'wp_oembed_add_discovery_links' , 10 ); //禁用嵌入代码oembed |
禁止加载WP自带的jquery.js
1 2 3 4 5 6 7 8 | //禁止加载WP自带的jquery.js if ( !is_admin() ) { // 后台不禁止 function my_init_method() { wp_deregister_script( 'jquery' ); // 取消原有的 jquery 定义 } add_action( 'init' , 'my_init_method' ); } wp_deregister_script( 'l10n' ); |

加微信交流
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架