Created
May 8, 2014 09:36
-
-
Save mapleobserver/dec89405735e68be2e8a to your computer and use it in GitHub Desktop.
隐藏 Wordpress 版本信息
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //将下列代码添加到当前主题的 functions.php 中 | |
| // 同时删除 head 和 feed 中的 WP 版本号 | |
| function ludou_remove_wp_version() { | |
| return ''; | |
| } | |
| add_filter('the_generator', 'ludou_remove_wp_version'); | |
| // 隐藏 js/css 附加的 WP 版本号 | |
| function ludou_remove_wp_version_strings( $src ) { | |
| global $wp_version; | |
| parse_str(parse_url($src, PHP_URL_QUERY), $query); | |
| if ( !empty($query['ver']) && $query['ver'] === $wp_version ) { | |
| // 用 WP 版本号 + 12.8 来替代 js/css 附加的版本号 | |
| // 既隐藏了 WordPress 版本号,也不会影响缓存 | |
| // 建议把下面的 12.8 替换成其他数字,以免被别人猜出 | |
| $src = str_replace($wp_version, $wp_version + 12.8, $src); | |
| } | |
| return $src; | |
| } | |
| add_filter( 'script_loader_src', 'ludou_remove_wp_version_strings' ); | |
| add_filter( 'style_loader_src', 'ludou_remove_wp_version_strings' ); | |
| //隐藏 WP 后台版本信息 | |
| add_filter('admin_footer_text', 'left_admin_footer_text'); | |
| function left_admin_footer_text($text) { | |
| // 左边信息改成自己的站点 | |
| $text = '感谢访问XXXX'; | |
| return $text; | |
| } | |
| add_filter('update_footer', 'right_admin_footer_text', 11); | |
| function right_admin_footer_text($text) { | |
| // 隐藏右边版本信息 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment