如何添加自定义的css登录和管理?

时间:2016-11-03 作者:glvr

我为登录和管理页面定制了CSS。

是否可以像我在下面所做的那样添加它,或者是否有更好的替代方案?

function custom_admin_css() {
    wp_enqueue_style( \'custom_admin_css\', get_template_directory_uri() . \'/css/admin.css\', array(), filemtime( get_template_directory() . \'/css/admin.css\' ) );
}
add_action( \'login_enqueue_scripts\', \'custom_admin_css\', 10 );
add_action( \'admin_enqueue_scripts\', \'custom_admin_css\', 10 );

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

这很好,这是将CSS添加到登录页面的正确方法。但您也可以通过以下代码更改登录页CSS-

function the_dramatist_custom_login_css() {
    echo \'<style type="text/css"> //Write your css here </style>\';
}
add_action(\'login_head\', \'the_dramatist_custom_login_css\');
这实际上是在登录页面内联打印CSS代码。对于管理员CSS,您的方式是正确的。

SO网友:Zaheer Abbas

有时,您必须将CSS添加到借助jQuery创建的内容中,这样,如果jQuery代码加载到页脚中,上述方法将无法工作。您也可以使用下面的代码。

function the_king_custom_login_css() {
    echo \'<style type="text/css">
    .nsl-container {
        text-align:center !important;
    }
    </style>\';
}
add_action(\'wp_footer\', \'the_king_custom_login_css\');

SO网友:infomasud

如中所述here 您可以执行以下操作:

// custom login for theme
function childtheme_custom_login() {
   echo \'<link rel="stylesheet" type="text/css" href="\' . 
   get_bloginfo(\'stylesheet_directory\') . \'/customlogin.css" />\';
}

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

another way for plugin:

如果您想从插件中为登录页面加载额外的css,可以执行以下操作:

我假设您了解wp插件开发的基础知识。

在插件目录中创建css目录创建登录。css文件。

在init函数中添加这个。

  public static function init(){
       //other function as your need
      add_action( \'login_enqueue_scripts\', __CLASS__.\'::custom_login_css\', 10 );
   }
然后您可以编写这样的函数。

public static function custom_login_css(){
        wp_enqueue_style(\'custom_login_css\', plugins_url(\'/css/login.css\', __FILE__), [], \'1.0.0\');
    }

相关推荐