返回
查看: 7|回复: 0
WordPress中文版(网站博客程序) v7.0.2 正式版-优化教程
网络资源

WordPress中文版(网站博客程序) v7.0.2 正式版-优化教程

[复制链接]
yazou yazou 2026-7-18 00:00:00 7 阅读

6075

主题

0

回帖

3945

积分

超级版主

积分
3945
WordPress中文版是全球广泛使用的免费开源网站博客程序.WordPress最新版是一种采用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设自己的网站,也可以把WordPress当作博客到大型网站的内容管理系统(CMS).WordPress程序是免费的开源项目,在GNU通用公共许可证下授权发布.


下载地址
WordPress中文版(网站博客程序) v7.0.2 正式版-优化教程


WordPress新版必备优化代码:
  1. <!--添加优化代码到主题目录functions.php文件-->
  2. /*彻底关闭自动更新(核心程序/主题/插件/翻译自动更新*/
  3. add_filter('automatic_updater_disabled', '__return_true');
  4. /*关闭更新检查定时作业*/
  5. remove_action('init', 'wp_schedule_update_checks');
  6. /*移除已有的版本检查定时作业*/
  7. wp_clear_scheduled_hook('wp_version_check');
  8. /*移除已有的插件更新定时作业*/
  9. wp_clear_scheduled_hook('wp_update_plugins');
  10. /*移除已有的主题更新定时作业*/
  11. wp_clear_scheduled_hook('wp_update_themes');
  12. /*移除已有的自动更新定时作业*/
  13. wp_clear_scheduled_hook('wp_maybe_auto_update');
  14. /*移除后台内核更新检查*/
  15. remove_action( 'admin_init', '_maybe_update_core' );
  16. /*移除后台插件更新检查*/
  17. remove_action( 'load-plugins.php', 'wp_update_plugins' );
  18. remove_action( 'load-update.php', 'wp_update_plugins' );
  19. remove_action( 'load-update-core.php', 'wp_update_plugins' );
  20. remove_action( 'admin_init', '_maybe_update_plugins' );
  21. /*移除后台主题更新检查*/
  22. remove_action( 'load-themes.php', 'wp_update_themes' );
  23. remove_action( 'load-update.php', 'wp_update_themes' );
  24. remove_action( 'load-update-core.php', 'wp_update_themes' );
  25. remove_action( 'admin_init', '_maybe_update_themes' );
  26. /*关闭程序更新提示*/
  27. add_filter( 'pre_site_transient_update_core', function($a){ return null; });
  28. /*关闭插件更新提示*/
  29. add_filter('pre_site_transient_update_plugins', function($a){return null;});
  30. /*关闭主题更新提示*/
  31. add_filter('pre_site_transient_update_themes', function($a){return null;});
  32. //关闭WordPress的XML-RPC功能
  33. add_filter('xmlrpc_enabled', '__return_false');
  34. /* 关闭XML-RPC的pingback端口 */
  35. add_filter( 'xmlrpc_methods', 'remove_xmlrpc_pingback_ping' );
  36. function remove_xmlrpc_pingback_ping( $methods ) {
  37. unset( $methods['pingback.ping'] );
  38. return $methods;
  39. }
  40. //禁用 pingbacks, enclosures, trackbacks
  41. remove_action( 'do_pings', 'do_all_pings', 10 );
  42. //去掉 _encloseme 和 do_ping 操作
  43. remove_action( 'publish_post','_publish_post_hook',5 );
  44. /* 禁止加载s.w.org获取表情和头像 */
  45. remove_action('wp_head', 'print_emoji_detection_script', 7 );
  46. remove_action('admin_print_scripts','print_emoji_detection_script');
  47. remove_action('wp_print_styles', 'print_emoji_styles');
  48. remove_action('admin_print_styles', 'print_emoji_styles');
  49. function remove_dns_prefetch( $hints, $relation_type ) {
  50. if ( 'dns-prefetch' === $relation_type ) {
  51. return array_diff( wp_dependencies_unique_hosts(), $hints );
  52. }
  53. return $hints;
  54. }
  55. add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );
  56. /* 完全禁止REST API、移除wp-json链接 */
  57. function lerm_disable_rest_api( $access ) {
  58.         return new WP_Error(
  59.                 'Stop!',
  60.                 'Soooooryyyy',
  61.                 array(
  62.                         'status' => 403,
  63.                 )
  64.         );
  65. }
  66. add_filter( 'rest_authentication_errors', 'lerm_disable_rest_api' );
  67. remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
  68. /* 禁止查询网站静态资源连接版本字符 */
  69. function _remove_script_version ( $src ){
  70.   $parts = explode( '?', $src );
  71.   return $parts[0];
  72. }
  73. add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
  74. add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
  75. /* 移除前端网页源代码内的头部冗余代码 */
  76. remove_action( 'wp_head', 'feed_links_extra', 3 );
  77. remove_action( 'wp_head', 'rsd_link' );
  78. remove_action( 'wp_head', 'wlwmanifest_link' );
  79. remove_action( 'wp_head', 'index_rel_link' );
  80. remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
  81. remove_action( 'wp_head', 'wp_generator' );
  82. /* 禁止新版文章编辑器加载前端样式 */
  83. function wpassist_remove_block_library_css(){
  84.     wp_dequeue_style( 'wp-block-library' );
  85. }
  86. remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
  87. add_action( 'wp_enqueue_scripts', 'wpassist_remove_block_library_css' );
  88. /* 移除新版本站点健康状态面板和菜单项 */
  89. add_action( 'admin_menu', 'remove_site_health_menu' );
  90. function remove_site_health_menu(){
  91. remove_submenu_page( 'tools.php','site-health.php' );
  92. }
  93. /* 禁用5.5版后自带的XML站点地图 */
  94. add_filter( 'wp_sitemaps_enabled', '__return_false' );
  95. /* 移除前后台顶部工具栏指定菜单 */
  96. function admin_bar_item ( WP_Admin_Bar $admin_bar ) {
  97.         $admin_bar->remove_menu('wp-logo'); //移动wp的logo
  98.         $admin_bar->remove_menu('site-name'); //移动站点名称
  99.         $admin_bar->remove_menu('updates'); //移动更新提示
  100.         $admin_bar->remove_menu('comments'); //移动评论提示
  101.         /*$admin_bar->remove_menu('new-content');        //移除新建按钮  */
  102. }
  103. add_action( 'admin_bar_menu', 'admin_bar_item', 500 );
  104. //移除后台仪表盘站点健康状态面板
  105. add_action('wp_dashboard_setup', 'remove_site_health_dashboard_widget');
  106. function remove_site_health_dashboard_widget()
  107. {
  108.     remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  109. }
  110. //移除后台仪表盘菜单:站点健康状态
  111. add_action( 'admin_menu', 'remove_site_health_menu' );
  112. function remove_site_health_menu(){
  113.         remove_submenu_page( 'tools.php','site-health.php' );
  114. }
  115. //移除后台仪表盘菜单:活动、新闻
  116. function bzg_remove_dashboard_widgets() {
  117.         global $wp_meta_boxes;
  118.         #移除 "活动"
  119.         unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);
  120.         #移除 "WordPress 新闻"
  121.         unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  122. }
  123. add_action('wp_dashboard_setup', 'bzg_remove_dashboard_widgets' );
  124. //移除后台仪表盘菜单:帮助
  125. function bzg_remove_help() {
  126.         get_current_screen()->remove_help_tabs();
  127. }
  128. add_action('admin_head', 'bzg_remove_help');
  129. //移除后台页面title标题的wordpress后缀
  130. add_filter('admin_title', 'delAdminTitle', 10, 2);
  131. function delAdminTitle($admin_title, $title){
  132.     return $title.' ‹ '.get_bloginfo('name');
  133. }
  134. //移除登陆页面title标题的wordpress后缀
  135. add_filter('login_title', 'remove_login_title', 10, 2);
  136. function remove_login_title($login_title, $title){
  137.         return $title.' ‹ '.get_bloginfo('name');
  138. }
  139. /* 彻底禁止4.4+版之后响应式图片功能及缩略图裁剪功能*/
  140. // 禁止生成图像尺寸
  141. function zm_customize_image_sizes( $sizes ){
  142.         unset( $sizes[ 'thumbnail' ]);
  143.         unset( $sizes[ 'medium' ]);
  144.         unset( $sizes[ 'medium_large' ] );
  145.         unset( $sizes[ 'large' ]);
  146.         unset( $sizes[ 'full' ] );
  147.         unset( $sizes['1536x1536'] );
  148.         unset( $sizes['2048x2048'] );
  149.         return $sizes;
  150. }
  151. add_filter( 'intermediate_image_sizes_advanced', 'zm_customize_image_sizes' );
  152. // 禁止缩放图片尺寸
  153. add_filter('big_image_size_threshold', '__return_false');
  154. // 禁止生成其它图像尺寸
  155. function shapeSpace_disable_other_image_sizes() {
  156.         // 禁止通过set_post_thumbnail_size()函数生成的图片尺寸
  157.         remove_image_size('post-thumbnail');
  158.         // 禁止添加其它图像尺寸
  159.         remove_image_size('another-size');
  160. }
  161. add_action('init', 'shapeSpace_disable_other_image_sizes');
  162. //切换经典文章编辑器(v5.x开始默认古腾堡编辑器)
  163. add_filter('use_block_editor_for_post', '__return_false');
  164. //替换评论用户头像链接为国内镜像加速访问
  165. add_filter('get_avatar', function ($avatar) {
  166. return str_replace([
  167. 'www.gravatar.com/avatar/',
  168. '0.gravatar.com/avatar/',
  169. '1.gravatar.com/avatar/',
  170. '2.gravatar.com/avatar/',
  171. 'secure.gravatar.com/avatar/',
  172. 'cn.gravatar.com/avatar/'
  173. ], 'cravatar.cn/', $avatar);
  174. });
  175. //取消内容转义
  176. remove_filter('the_content', 'wptexturize');
  177. //取消摘要转义
  178. remove_filter('the_excerpt', 'wptexturize');
  179. //取消评论转义
  180. remove_filter('comment_text', 'wptexturize');
  181. //禁止转义引号字符
  182. remove_filter('the_content', 'wptexturize');    // 禁止英文引号转义为中文引号
  183. //文章插入图片自动移除 img 的 width、height、class 属性;
  184. add_filter( 'post_thumbnail_html', 'fanly_remove_images_attribute', 10 );
  185. add_filter( 'image_send_to_editor', 'fanly_remove_images_attribute', 10 );
  186. function fanly_remove_images_attribute( $html ) {
  187. //$html = preg_replace( '/(width|height)="d*"s/', "", $html );
  188. $html = preg_replace( '/width="(d*)"s+height="(d*)"s+class="[^"]*"/', "", $html );
  189. $html = preg_replace( '/  /', "", $html );
  190. return $html;
  191. }
  192. //自适应图片删除width和height
  193. function ludou_remove_width_height_attribute($content){
  194.   preg_match_all('/<[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg|.png.webp]))['|"].*?[/]?>/', $content, $images);
  195.   if(!empty($images)) {
  196.     foreach($images[0] as $index => $value){
  197.       $new_img = preg_replace('/(width|height)="d*"s/', "", $images[0][$index]);
  198.       $content = str_replace($images[0][$index], $new_img, $content);
  199.     }
  200.   }
  201.   return $content;
  202. }
  203. //判断是否是移动设备浏览
  204. if(wp_is_mobile()) {
  205.    #删除文章内容中img的width和height属性
  206.    add_filter('the_content', 'ludou_remove_width_height_attribute', 99);
  207. }
  208. /* 删除文章时删除图片附件 */
  209. function delete_post_and_attachments($post_ID) {
  210. global $wpdb;
  211. #删除特色图片
  212. $thumbnails = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id' AND post_id = $post_ID" );
  213. foreach ( $thumbnails as $thumbnail ) {
  214. wp_delete_attachment( $thumbnail->meta_value, true );
  215. }
  216. #删除图片附件
  217. $attachments = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_parent = $post_ID AND post_type = 'attachment'" );
  218. foreach ( $attachments as $attachment ) {
  219. wp_delete_attachment( $attachment->ID, true );
  220. }
  221. $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id' AND post_id = $post_ID" );
  222. }
  223. add_action('before_delete_post', 'delete_post_and_attachments');
复制代码

新版变化
News & Announcements – WordPress.org
https://cn.wordpress.org/download/releases/

系统要求
WordPress 5.x以上版本最低运行需求:
PHP5.6或更高版,建议PHP7.2稳定版
MySQL5.6或更高版,建议用5.6稳定版



     相关文件下载地址
    夸克网盘   百度网盘
--------------------------------------------------------------1.本站所提供的压缩包若无特别说明,解压密码均为www.4mf.net;
2.下载后文件若为压缩包格式,请安装7Z软件或者其它压缩软件进行解压;
3.文件比较大的时候,建议使用下载工具进行下载,浏览器下载有时候会自动中断,导致下载错误;
4.资源可能会由于内容问题被和谐,导致下载链接不可用,遇到此问题,请到文章页面进行留言反馈,以便及时进行更新;
5.下载资源版权归作者所有;本站所有资源均来源于网络,仅供学习使用,请支持正版!下载后请注意杀毒。
回复

使用道具 举报

评论
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Loading...
关注公众号
Archiver|小黑屋|yazou! 劰载中...

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部