

'/style3.css' ) Īdd_action( 'wp_enqueue_scripts', 'my_enqueue_styles' ) Wp_register_style( 'style3', get_template_directory_uri(). Wp_register_style( 'style2', get_template_directory_uri(). Wp_register_style( 'style1', get_template_directory_uri(). add_action('init', 'my_register_styles') The typical scenario of using both functions is when you want to register scripts/styles on theme init, and then enqueue them conditionally on some pages, e.g. You probably already know that, but there is a second difference wp_register_* can be used in every hook, even in an early hook like init, but wp_enqueue_* should be used on wp_enqueue_scripts hook (or admin_enqueue_scripts for backend) 1. Main difference between wp_enqueue_* and respective wp_register_* functions, is that the first adds scripts/styles to the queue, the second prepares scripts/styles to be added. While the wp_enqueue_style() has all the parameters that present in wp_register_style() ( $handle, $src, $deps, $ver, $media) then why should I repeat them? Or, what exactly the purpose of wp_register_style() other than wp_enqueue_style()?įirst of all let's say that regarding these functions what is valid for styles is exactly valid for scripts, but there are some exceptions to the contrary explained in the answer. Wp_enqueue_style( 'mobile-menu-styles', get_template_directory_uri(). Wp_enqueue_style( 'menu-styles', get_template_directory_uri().

Wp_enqueue_style( 'site-styles', get_template_directory_uri(). I enqueued them like: add_action( 'wp_enqueue_scripts', 'wpse20131025_styles' ) But just now I got an answer from s_ha_dum saying that using the wp_register_style() would make theme child theme-friendly - I wonder, without the wp_register_style() I's using only the wp_enqueue_style() and my theme's working fine with the enqueued styles. But in enqueuing the styles, I used only the wp_enqueue_style() with all its parameters. When enqueued the scripts, I used wp_register_script() first, and then enqueued with wp_enqueue_script() - because I got that's the proper way of enqueuing the scripts.
#WP ENQUEUE STYLE HOW TO#
Currently I'm working on a theme, and did some styles and scripts enqueue. I’ve written about how to add custom CSS to WordPress.Instead of modifying your theme’s style.css file, creating a child theme, or using a plugin, I suggest you simply create a new stylesheet with the additional CSS rules and include them in WordPress using the wpenqueuestyle function.
