WordPress个性化修改

   

WordPress个性化修改

登录页去Logo

function bzg_remove_loginlogo() {
    echo '<style>#login > h1 a {background: none;}</style>';
}
add_action('login_head', 'bzg_remove_loginlogo');

删除顶部工具条中的菜单

function bzg_remove_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('wp-logo'); //左上角WP Logo图标
    $wp_admin_bar->remove_menu('comments'); //评论按钮
    $wp_admin_bar->remove_menu('new-content'); //新建按钮
    $wp_admin_bar->remove_menu('view-site'); //查看网站链接
}
add_action('wp_before_admin_bar_render', 'bzg_remove_bar');

删除左侧菜单

function bzg_remove_menus() {
    remove_menu_page('index.php'); //仪表盘
    remove_menu_page('edit.php'); //文章
    remove_menu_page('edit.php?post_type=page'); //页面
    remove_menu_page('edit-comments.php'); //评论
    remove_menu_page('upload.php'); //媒体
    remove_menu_page('themes.php'); //外观
    remove_menu_page('plugins.php'); //插件
    remove_menu_page('users.php'); //用户
    remove_menu_page('profile.php'); //个人资料
    remove_menu_page('tools.php'); //工具
    remove_menu_page('options-general.php'); //设置
}
add_action('admin_menu', 'bzg_remove_menus');

替换页脚版权信息

function bzg_admin_footer() {
    return '<span id="footer-thankyou">Copyright © ' . get_option('blogname') . '</span>';
}
add_filter('admin_footer_text', 'bzg_admin_footer');

去除后台页面Title标签中的“wordpress”字样

function bzg_filter_admin_title($admin_title, $title) {
    return rtrim($admin_title, ' — WordPress');
}
add_filter('admin_title', 'bzg_filter_admin_title', 10, 2);

去除登录页面Title标签中的“wordpress”字样

function bzg_filter_login_title($login_title, $title) {
    return rtrim($login_title, ' — WordPress');
}
add_filter('login_title', 'bzg_filter_login_title', 10, 2);

为登录页添加背景

function bzg_login_head() {
    $img = get_template_directory_uri() . '/statics/img/login-bg.jpg';
    echo "<style>
            body {
                background: url({$imgdir}) #ffffff center center no-repeat;
                background-size: cover;
            }
            .login form {
                box-shadow: 0px 0px 5px rgba(0,0,0,.3);
            }
        </style>";
}
add_action('login_head', 'bzg_login_head');

删除帮助

function bzg_remove_help() {
    get_current_screen()->remove_help_tabs();
}
add_action('admin_head', 'bzg_remove_help');登录页去Logo
function bzg_remove_loginlogo() {
    echo '<style>#login > h1 a {background: none;}</style>';
}
add_action('login_head', 'bzg_remove_loginlogo');

隐藏个人资料页面部份表单项

function bzg_remove_profile_option($user_id) {
    echo '<style>
        #your-profile h2,
        .user-syntax-highlighting-wrap,
        .user-rich-editing-wrap,
        .user-comment-shortcuts-wrap,
        .user-admin-bar-front-wrap,
        .user-language-wrap,
        .user-user-login-wrap,
        .user-first-name-wrap,
        .user-last-name-wrap,
        .user-url-wrap,
        .user-description-wrap {
            display:none;
        }
        </style>';
}
add_action('show_user_profile', 'bzg_remove_profile_option', 10, 1);
add_action('edit_user_profile', 'bzg_remove_profile_option', 10, 1);

```## 删除仪表盘模块
```php
function bzg_remove_dashboard_widgets() {
    global $wp_meta_boxes;
    //删除 "活动" 模块
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);
    //删除 "WordPress 新闻" 模块
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
}
add_action('wp_dashboard_setup', 'bzg_remove_dashboard_widgets' );

在隐藏仪表盘菜单后,可能希望登录后台显示某个特定页面,那么可以通过以下代码实现跳转

//登录后台跳转
function bzg_login_redirect($redirect_to, $request, $user) {
    if(!isset($user->roles)) return;
    return $url;
}
add_filter('login_redirect', 'bzg_login_redirect', 10, 3);
//在仪表盘页面时跳转
if(is_admin() && 'index.php' == $GLOBALS['pagenow']) {
    header("location:$url");
}

清理干净后,就可以开始定制自己的个性化后台了,使用add_menu_page函数和admin_menu钩子就可以添加菜单。

发表评论