I try to style the login page in my theme. Very simple:
add_action( 'login_enqueue_scripts', function()
{
wp_enqueue_style( 'TEST', get_template_directory_uri() . '/css/login.css' );
});
Unfortunately, it doesn’t work as expected. The link element appears in the body of the login page, very late.
Rendered output:
<link rel='stylesheet' id='TEST-css' href='http://themes.wp/t5-theme-base/css/login.css?ver=3.9-alpha' type='text/css' media='all' />
<div class="clear"></div>
</body>
</html>
This is wrong, how can I print the link element in the head?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
For every enqueue action, there is a corresponding print_styles action:
wp_enqueue_scripts→wp_print_stylesadmin_enqueue_scripts→admin_print_stylescustomize_controls_enqueue_scripts→customize_controls_print_styles
Not for the login page. There is no login_print_styles action or function, so your stylesheets are thrown out on do_action( 'login_footer' );.
But there is a simple fix:
if ( ! has_action( 'login_enqueue_scripts', 'wp_print_styles' ) )
add_action( 'login_enqueue_scripts', 'wp_print_styles', 11 );
WordPress will now print all link elements registered for that page at the proper place, the head element, right after the built-in stylesheets.
Result:
<link rel='stylesheet' id='dashicons-css' href='http://git.wp/wp-includes/css/dashicons.min.css?ver=3.9-alpha' type='text/css' media='all' />
<link rel='stylesheet' id='wp-admin-css' href='http://git.wp/wp-admin/css/wp-admin.min.css?ver=3.9-alpha' type='text/css' media='all' />
<link rel='stylesheet' id='buttons-css' href='http://git.wp/wp-includes/css/buttons.min.css?ver=3.9-alpha' type='text/css' media='all' />
<link rel='stylesheet' id='colors-fresh-css' href='http://git.wp/wp-admin/css/colors.min.css?ver=3.9-alpha' type='text/css' media='all' />
<!--[if lte IE 7]>
<link rel='stylesheet' id='ie-css' href='http://git.wp/wp-admin/css/ie.min.css?ver=3.9-alpha' type='text/css' media='all' />
<![endif]-->
<link rel='stylesheet' id='TEST-css' href='http://themes.wp/t5-theme-base/css/login.css?ver=3.9-alpha' type='text/css' media='all' />
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0