説明
login_enqueue_scripts は、ログイン画面で、CSS・JavaScriptを読み込むためのアクションです。
基本構文
do_action( 'login_enqueue_scripts' )
引数
引数はありません。
戻り値
引数はありません。
使い方(サンプル)
add_action( 'login_enqueue_scripts', function() {
wp_enqueue_style( 'my-login', get_theme_file_uri( 'login.css' ) );
} );
注意点
- ログイン画面のロゴ変更などに使います。
実務での使いどころ
- ログインページ(
wp-login.php)の見た目を、独自のCSSで、変えるとき。 - ログインページに、独自のスクリプトを、読み込むとき。
よくあるミスと対処
wp_enqueue_scriptsを使っている。このフックは、ログインページでは、実行されない。- 管理画面用の
admin_enqueue_scriptsを使っている。ログインページでは、実行されない。 - CSSの読み込みを、直接
<link>で書いている。
NG例
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style( 'my-login', get_theme_file_uri( '/css/login.css' ) ); // ログインページでは実行されない
} );
OK例
add_action( 'login_enqueue_scripts', function () {
wp_enqueue_style( 'my-login', get_theme_file_uri( '/css/login.css' ), array(), '1.0.0' );
} );
使い分け早見表
| フック | 対象 |
|---|---|
login_enqueue_scripts |
ログインページ |
wp_enqueue_scripts |
フロント |
admin_enqueue_scripts |
管理画面 |
関連項目
wp_enqueue_scripts、admin_enqueue_scripts、wp_enqueue_script()
公式リファレンス:login_enqueue_scripts | WordPress Developer Resources

コメント