On this page
wp_enqueue_style( string $handle, string $src = '', string[] $deps = array(), string|bool|null $ver = false, string $media = 'all' )
Enqueue a CSS stylesheet.
Description
Registers the style if source provided (does NOT overwrite) and enqueues.
See also
Parameters
$handlestring Required-
Name of the stylesheet. Should be unique.
$srcstring Optional-
Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
Default:
'' $depsstring[] Optional-
An array of registered stylesheet handles this stylesheet depends on.
Default:
array() $verstring|bool|null Optional-
String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version.
If set to null, no version is added.Default:
false $mediastring Optional-
The media for which this stylesheet has been defined.
Default'all'. Accepts media types like'all','print'and'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.Default:
'all'
More Information
Usage
A safe way to add/enqueue a stylesheet file to the WordPress generated page.
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Notes
- If you are going to use some jQuery UI features you might have to provide your own CSS file: WordPress core does not have a full jQuery UI theme!
- Default styles that are loaded via WordPress Core can be discerned via the source code on the default styles page.
Source
File: wp-includes/functions.wp-styles.php. View all references
function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
$wp_styles = wp_styles();
if ( $src ) {
$_handle = explode( '?', $handle );
$wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
}
$wp_styles->enqueue( $handle );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_styles() wp-includes/functions.wp-styles.php | Initialize $wp_styles if it has not been set. |
Used By
| Used By | Description |
|---|---|
| wp_enqueue_classic_theme_styles() wp-includes/script-loader.php | Loads classic theme styles on classic themes in the frontend. |
| wp_enqueue_stored_styles() wp-includes/script-loader.php | Fetches, processes and compiles stored core styles, then combines and renders them to the page. |
| _wp_theme_json_webfonts_handler() wp-includes/script-loader.php | Runs the theme.json webfonts handler. |
| wp_enqueue_global_styles_css_custom_properties() wp-includes/script-loader.php | Function that enqueues the CSS Custom Properties coming from theme.json. |
| wp_enqueue_block_style() wp-includes/script-loader.php | Enqueues a stylesheet for a specific block. |
| wp_enqueue_editor_format_library_assets() wp-includes/script-loader.php | Enqueues the assets required for the format library within the block editor. |
| wp_enqueue_global_styles() wp-includes/script-loader.php | Enqueues the global styles defined via theme.json. |
| WP_Block::render() wp-includes/class-wp-block.php | Generates the render output for the block. |
| wp_enqueue_editor_block_directory_assets() wp-includes/script-loader.php | Enqueues the assets required for the block directory within the block editor. |
| enqueue_block_styles_assets() wp-includes/script-loader.php | Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend. |
| wp_common_block_scripts_and_styles() wp-includes/script-loader.php | Handles the enqueueing of block scripts and styles that are common to both the editor and the front-end. |
| wp_enqueue_registered_block_scripts_and_styles() wp-includes/script-loader.php | Enqueues registered block scripts and styles, depending on current rendered context (only enqueuing editor scripts while in context of the editor). |
| register_and_do_post_meta_boxes() wp-admin/includes/meta-boxes.php | Registers the default post meta boxes, and runs the |
| wp_enqueue_code_editor() wp-includes/general-template.php | Enqueues assets needed by the code editor for the given settings. |
| _WP_Editors::enqueue_default_editor() wp-includes/class-wp-editor.php | Enqueue all editor scripts. |
| WP_Widget_Media_Audio::enqueue_admin_scripts() wp-includes/widgets/class-wp-widget-media-audio.php | Loads the required media files for the media manager and scripts for media widgets. |
| WP_Widget_Media_Audio::enqueue_preview_scripts() wp-includes/widgets/class-wp-widget-media-audio.php | Enqueue preview scripts. |
| WP_Widget_Media_Video::enqueue_preview_scripts() wp-includes/widgets/class-wp-widget-media-video.php | Enqueue preview scripts. |
| enqueue_embed_scripts() wp-includes/embed.php | Enqueues embed iframe default CSS and JS. |
| WP_Customize_Nav_Menus::enqueue_scripts() wp-includes/class-wp-customize-nav-menus.php | Enqueues scripts and styles for Customizer pane. |
| login_header() wp-login.php | Output the login page header. |
| wp_dashboard_setup() wp-admin/includes/dashboard.php | Registers dashboard widgets. |
| WP_Internal_Pointers::enqueue_scripts() wp-admin/includes/class-wp-internal-pointers.php | Initializes the new feature pointers. |
| iframe_header() wp-admin/includes/template.php | Generic Iframe header for use with Thickbox. |
| wp_iframe() wp-admin/includes/media.php | Outputs the iframe to display the media upload page. |
| Custom_Image_Header::css_includes() wp-admin/includes/class-custom-image-header.php | Set up the enqueue for the CSS files |
| Custom_Background::admin_load() wp-admin/includes/class-custom-background.php | Sets up the enqueue for the CSS & JavaScript files. |
| WP_Customize_Manager::customize_preview_init() wp-includes/class-wp-customize-manager.php | Prints JavaScript settings. |
| add_thickbox() wp-includes/general-template.php | Enqueues the default ThickBox js and css. |
| wp_admin_css() wp-includes/general-template.php | Enqueues or directly prints a stylesheet link to the specified CSS file. |
| wp_auth_check_load() wp-includes/functions.php | Loads the auth check for monitoring whether the user is still logged in. |
| WP_Admin_Bar::initialize() wp-includes/class-wp-admin-bar.php | Initializes the admin bar. |
| wp_enqueue_media() wp-includes/media.php | Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs. |
| wp_video_shortcode() wp-includes/media.php | Builds the Video shortcode output. |
| wp_playlist_scripts() wp-includes/media.php | Outputs and enqueues default scripts and styles for playlists. |
| wp_audio_shortcode() wp-includes/media.php | Builds the Audio shortcode output. |
| WP_Customize_Color_Control::enqueue() wp-includes/customize/class-wp-customize-color-control.php | Enqueue scripts/styles for the color picker. |
| WP_Customize_Widgets::enqueue_scripts() wp-includes/class-wp-customize-widgets.php | Enqueues scripts and styles for Customizer panel and export data to JavaScript. |
| _WP_Editors::enqueue_scripts() wp-includes/class-wp-editor.php |
Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_enqueue_style