📅  最后修改于: 2023-12-03 14:48:34.509000             🧑  作者: Mango
The wp_enqueue_style
function is a fundamental feature in WordPress that enables developers to add custom CSS stylesheets to their themes. It is used to register and enqueue external stylesheets for a WordPress site.
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
$handle
(string): A unique identifier for the stylesheet. $src
(string): The URL of the stylesheet file.$deps
(array): An array of handles (string) for any stylesheets the current stylesheet depends on. Include any dependencies as an array of strings.$ver
(string|boolean|null): A version number string for the stylesheet. This parameter is optional, and if no version number is required, it can be passed as null. time()
can be used to add a version number that updates whenever a change is made to the stylesheet$media
(string): The media type for which this stylesheet has been defined.wp_enqueue_style('main-style', get_stylesheet_directory_uri() . 'assets/css/bootstrap.min.css', [], time(), 'all' );
This example registers the Bootstrap stylesheet in WordPress through the wp_enqueue_style
function. The function includes the main-style
as the unique identifier, and the URL for the stylesheet is driven by the get_stylesheet_directory_uri()
function that locates the proper path to the main theme stylesheet directory.
wp_enqueue_style
is a valuable function in the WordPress developer toolkit. It enables developers to add their custom CSS stylesheets to their WordPress themes easily. By using this function, you can make your WordPress site more visually appealing and provide the necessary styling for your theme.