LOGIN_ENQUEUE_SCRIPTS不会删除默认样式

时间:2016-04-15 作者:Kevin Mamaqi

UPDATED: 解决方案是使用login_head 如果需要覆盖–@Jevuska

更新到WP 4.5 my styles以自定义登录页面后,不要覆盖默认WP样式。这是我的代码:

function my_login_logo() { ?>
    <style type="text/css">
        .login h1 a {
            background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/assets/images/logo.png);
            padding-bottom: 30px;
            width: 297px;
            height: 64px;
            background-size: 297px;
        }
        .login form {
          -webkit-box-shadow: 0 1px 6px rgba(0,0,0,.4);
          box-shadow: 0 1px 6px rgba(0,0,0,.4);
        }

        .login label {
          color: #333;
        }

        .login #nav a {
          color: #007CAD;
        }

        body, html {
          background: #fff;
        }
    </style>
<?php }
add_action( \'login_enqueue_scripts\', \'my_login_logo\' );

1 个回复
最合适的回答,由SO网友:Jevuska 整理而成

@Kevin,这里有几个选项如何覆盖登录页面的css。

通过login_enqueue_scripts

如果使用此挂钩,则需要创建与相同路径的css文件functions.php, 说login-style.css, 在内部添加代码,更改属性背景图像,如下所示background-image: url(assets/images/logo.png); (确保路径正确),并使用wp_enqueue_style 在里面functions.php. 我们使用login 作为手柄login-style.css, 它会将您的css置于默认WP样式之后。

add_action( \'login_enqueue_scripts\', \'my_login_logo\' );
function my_login_logo()
{
    wp_enqueue_style( \'login-custom-style\', get_stylesheet_directory_uri(). \'/login-style.css\', array(\'login\') );
}
Via公司login_head

由于您的css中有php代码,因此使用此挂钩,您的内联css代码将放在默认WP样式之后。

add_action( \'login_head\', \'my_login_logo\' );

相关推荐