This page redirects to an external site: https://developer.wordpress.org/reference/functions/wp_enqueue_style/
Languages: English • 日本語 Русский • (Add your language)
A safe way to add/enqueue a stylesheet file to the WordPress generated page.
<?php wp_enqueue_style( $handle, $src, $deps, $ver, $media ); ?>
Scripts and styles from a single action hook
/**
* Proper way to enqueue scripts and styles
*/
function theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
/*
* This example will work at least on WordPress 2.6.3,
* but maybe on older versions too.
*/
add_action( 'admin_init', 'my_plugin_admin_init' );
add_action( 'admin_menu', 'my_plugin_admin_menu' );
function my_plugin_admin_init() {
/* Register our stylesheet. */
wp_register_style( 'myPluginStylesheet', plugins_url('stylesheet.css', __FILE__) );
}
function my_plugin_admin_menu() {
/* Register our plugin page */
$page = add_submenu_page( 'edit.php',
__( 'My Plugin', 'myPlugin' ),
__( 'My Plugin', 'myPlugin' ),
'administrator',
__FILE__,
'my_plugin_manage_menu' );
/* Using registered $page handle to hook stylesheet loading */
add_action( 'admin_print_styles-' . $page, 'my_plugin_admin_styles' );
}
function my_plugin_admin_styles() {
/*
* It will be called only on your plugin admin page, enqueue our stylesheet here
*/
wp_enqueue_style( 'myPluginStylesheet' );
}
function my_plugin_manage_menu() {
/* Output our admin page */
}
wp_enqueue_style() is located in wp-includes/functions.wp-styles.php.
Enqueue Styles
Enqueue Scripts
Front-End Hooks
Admin Hooks
Login Hooks