以下代码片段,添加至自己的主题模板函数(functions.php)
添加登陆界面背景,每天从bing更新。
1
2
3
4
5
6
7
8
9
10
|
/**
* Login head.
*/
function custom_login_head(){
$str=file_get_contents(‘https://global.bing.com/HPImageArchive.aspx?idx=0&n=1’);
if(preg_match(“/<url>(.+?)<\/url>/ies”,$str,$matches)){
$imgurl=‘https://global.bing.com’.$matches[1];
echo‘<style type=”text/css”>body{background: url(‘.$imgurl.’);width:100%;height:100%;background-image:url(‘.$imgurl.’);-moz-background-size: 100% 100%;-o-background-size: 100% 100%;-webkit-background-size: 100% 100%;background-size: 100% 100%;-moz-border-image: url(‘.$imgurl.’) 0;background-repeat:no-repeat\9;background-image:none\9;}</style>‘;
}}
add_action(‘login_head’, ‘custom_login_head’);
|
修改登陆页的Logo.
1
2
3
4
5
6
7
|
/**
* Login Logo.
*/
function custom_login_logo() {
echo ‘<style type=”text/css”>h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/login-logo.png) !important; }</style>‘;
}
add_action(‘login_head’, ‘custom_login_logo’);
|
保护wp-admin目录
1
2
3
4
5
6
7
|
/**
* Protected WP-Login.
*/
function login_protection(){
if($_GET[‘key’] != ‘Login’)header(‘Location: https://moeclub.org/’);
}
add_action(‘login_enqueue_scripts’, ‘login_protection’);
|
移除WordPress版本号
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
/**
* Remove Version.
*/
function left_admin_footer($text) {
$text = ‘Hello, World! ‘;
return $text;
}
function right_admin_footer($text) {
}
remove_action( ‘wp_head’, ‘wp_generator’ ) ;
remove_action( ‘wp_head’, ‘wlwmanifest_link’ ) ;
remove_action( ‘wp_head’, ‘rsd_link’ ) ;
add_filter(‘admin_footer_text’, ‘left_admin_footer’);
add_filter(‘update_footer’, ‘right_admin_footer’, 11);
|
禁止WordPress更新
1
2
3
4
5
6
7
8
9
|
/**
* Close update.
*/
remove_action(‘admin_init’, ‘_maybe_update_core’);
remove_action(‘admin_init’, ‘_maybe_update_plugins’);
remove_action(‘admin_init’, ‘_maybe_update_themes’);
add_filter(‘pre_site_transient_update_core’, create_function(‘$a’, “return null;”));
add_filter(‘pre_site_transient_update_plugins’, create_function(‘$a’, “return null;”));
add_filter(‘pre_site_transient_update_themes’, create_function(‘$a’, “return null;”));
|
移除后台WordPress的LOGO
1
2
3
4
5
6
7
8
|
/**
* Remove their logo
*/
function annointed_admin_bar_remove() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(‘wp-logo’);
}
add_action(‘wp_before_admin_bar_render’, ‘annointed_admin_bar_remove’, 0);
|
禁止sw.org
1
2
3
4
5
6
7
8
9
10
|
/**
* Disable sw.org
*/
function remove_dns_prefetch( $hints, $relation_type ) {
if ( ‘dns-prefetch’ === $relation_type ) {
return array_diff( wp_dependencies_unique_hosts(), $hints );
}
return $hints;
}
add_filter( ‘wp_resource_hints’, ‘remove_dns_prefetch’, 10, 2 );
|
移除api.w.org
1
2
3
4
5
6
7
|
/**
* Remove api.w.org
*/
add_filter(‘rest_enabled’, ‘_return_false’);
add_filter(‘rest_jsonp_enabled’, ‘_return_false’);
remove_action(‘wp_head’, ‘rest_output_link_wp_head’, 10 );
remove_action(‘wp_head’, ‘wp_oembed_add_discovery_links’, 10 );
|
添加favicon.ico站点图标
-
- 修改header.php,在
head
标签内添加如下行:
- 修改header.php,在
1
|
<link rel=“shortcut icon” href=“<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico” />
|
- 将favicon.ico文件复制到WordPress根目录和主题根目录.
移除js,css版本号.
1
2
3
4
5
6
7
8
|
/**
* Remove src version.
*/
function remove_src_version( $src ){
return remove_query_arg( ‘ver’, $src );
}
add_filter( ‘script_loader_src’, ‘remove_src_version’, 15, 1 );
add_filter( ‘style_loader_src’, ‘remove_src_version’, 15, 1 );
|