一个懒散的博客

使用WordPress一些常用技巧

以下代码片段,添加至自己的主题模板函数(functions.php)

添加登陆界面背景,每天从bing更新

/**
 * 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');

保护wp-admin目录

/**
 * Protected WP-Login.
 */
function login_protection(){
 if($_GET['key'] != 'Login')header('Location: https://xx.com/');
}
add_action('login_enqueue_scripts', 'login_protection');

移除WordPress版本号

/**
 * Remove Version.
 */
remove_action( 'wp_head', 'wp_generator' ) ;
remove_action( 'wp_head', 'wlwmanifest_link' ) ;
remove_action( 'wp_head', 'rsd_link' ) ;

禁止WordPress更新

/**
 * 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

/**
 * 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);
赞(0)