Best spot for wp_register_script() and wp_register_style()

Scripts and styles can be registered on the wp_loaded hook and then later enqueued using wp_enqueue_scripts. Once the scripts and styles have been registered, they can be enqueued later using just the handles that they were originally registered with. // Register scripts/styles. They can be optionally enqueued later on. add_action( ‘wp_loaded’, ‘wpse_register_scripts’ ); function wpse_register_scripts() … Read more

I register and enqueue stylesheet but nothing is rendered

You’re doing well – just one thing you need to change, and I reckon it’s a totally reasonable mistake to make: This: add_action(‘wp_enqueue_styles’, ‘alpha_styles’); needs to become add_action(‘wp_enqueue_scripts’, ‘alpha_styles’); Why scripts? Because there is no WordPress action called wp_enqueue_styles. Although the functions are named wp_register_style & wp_enqueue_style, you still need to hook them to the … Read more

WordPress Register Style Called Incorrectly

The notice is quite obvious. It is telling you that you are not running wp_register_style() within the wp_enqueue_scripts hook. SOLUTION Move your wp_register_script() and wp_register_style() calls to inside your function which is hooked to wp_enqueue_scripts

How do I register/enqueue a custom CSS file?

Refer to the Codex entry for wp_enqueue_style(). Assuming you have a custom stylesheet, named custom.css, located in your Theme’s root directory: wp_enqueue_style( ‘mytheme-custom’, get_template_directory_uri() . ‘/custom.css’ ); You would put this in functions.php, inside a callback, hooked into an appropriate callback, like so: function wpse87681_enqueue_custom_stylesheets() { if ( ! is_admin() ) { wp_enqueue_style( ‘mytheme-custom’, get_template_directory_uri() … Read more

Load js/css files only on specific admin UI pages

The right hooks // Use both for scripts & styles *) wp_enqueue_scripts // (for the frontend) login_enqueue_scripts // (for the login screen) admin_enqueue_scripts // (for the admin dashboard) *) Read this article @wpdevel. Further reading in the Codex about the three hooks admin_menu network_admin_menu user_admin_menu On the admin_enqueue_scripts hook, you have an argument as well: … Read more

How to enqueue style before style.css

Enqueue the style.css too, and set normalize as dependency: if ( ! is_admin() ) { // Register early, so no on else can reserve that handle add_action( ‘wp_loaded’, function() { wp_register_style( ‘normalize’, // parent theme get_template_directory_uri() . ‘/css/normalize.css’ ); wp_register_style( ‘theme_name’, // current theme, might be the child theme get_stylesheet_uri(), [ ‘normalize’ ] ); }); … Read more

Why is style.css not being enqueued?

Theme stylesheets aren’t usually enqueued, they’re normally loaded using.. <link rel=”stylesheet” type=”text/css” media=”all” href=”https://wordpress.stackexchange.com/questions/14655/<?php bloginfo(“stylesheet_url’ ); ?>” /> So naturally you don’t see them(it) in the styles array.. You can of course(if you prefer) use an enqueue instead.