Function Reference/wp register style
Description
A safe way to register a CSS style file for later use with wp_enqueue_style().
Usage
<?php wp_register_style( $handle, $src, $deps, $ver, $media ) ?>
Use the wp_enqueue_scripts action to call this function. Calling it outside of an action can lead to problems. See #17916 for details.
Parameters
- $handle
- (string) (required) Name of the stylesheet (which should be unique as it is used to identify the script in the whole system).
- Default: None
- $src
- (string) (required) URL to the stylesheet. Example: 'http://example.com/css/mystyle.css'. You should never hardcode URLs to local styles, use Function Reference/plugins_url (for Plugins) and Function Reference/get_template_directory_uri (for Themes) to get a proper URL. Remote assets can be specified with a protocol-agnostic URL, i.e. '//otherdomain.com/css/theirstyle.css'.
- Default: None
- $deps
- (array) (optional) Array of handles of any stylesheets that this stylesheet depends on. Dependent stylesheets will be loaded before this stylesheet.
- Default: array()
- $ver
- (string|boolean) (optional) String specifying the stylesheet version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the stylesheet. The version is appended to the stylesheet URL as a query string, such as ?ver=3.5.1. By default, or if false, the WordPress version string is used. If null nothing is appended to the URL.
- Default: false
- $media
- (string) (optional) String specifying the media for which this stylesheet has been defined. Examples: 'all', 'screen', 'handheld', 'print'. See this list for the full range of valid CSS-media-types.
- Default: 'all'
Return Values
- (void)
- This function does not return a value.
Examples
Notes
- Uses global: (object) $wp_styles
Change Log
- Since: 2.1 (BackPress version: r79)
Source File
wp_register_style() is located in wp-includes/functions.wp-styles.php.
Related
Enqueue functions: wp_register_script(),
wp_deregister_script(),
wp_enqueue_script(),
wp_dequeue_script(),
wp_localize_script(),
wp_script_is(),
wp_register_style(),
wp_deregister_style(),
wp_enqueue_style(),
wp_dequeue_style(),
wp_style_is()
Enqueue actions:
admin_enqueue_scripts,
admin_print_scripts,
admin_print_scripts-(hookname),
wp_enqueue_scripts,
wp_print_scripts,
admin_print_styles,
admin_print_styles-(hookname),
wp_print_styles