The below function is used to include or register stylesheets, which takes various parameter. There are other parameters as well. Hooks are registered in functions.php file
wp_register_style( string $handle, string|false $src, string[] $deps = array(), string|bool|null $ver = false, string $media = 'all' ): bool
https://developer.wordpress.org/reference/functions/wp_register_style/
Note: The styles are registered using a add_action hook
Example:
add_action('wp_enqueue_scripts','myweb_enqueue');
Example
//the url needs to be http uri and not relative path.
//for loading local style sheet and converting that to uri
// you can use get_theme_file_uri function
wp_register_style('my_custom_style',get_theme_file_uri('custom.css'))
Note: wp_register_style only registers the style, but it doesn’t actually load the file.
To Load the file must enqueue the file with wp_enqueue_style function. Though it is not mandatory to use wp_register_style, but it is a good practice to register the stylesheet using wp_register_style. Also if a css file is registered using wp_register_style, we only need to provide the identifier/file handler that is first argument of register to wp_enqueue_style. Example
wp_enqueue_style('unique_identifier_string')// it can be same as used in //wp_register_style
Leave a Reply