Reguisters a CSS stylesheet.
Description
See also
Parameters
-
$handlestring required -
Name of the stylesheet. Should be unique.
-
$srcstring | false required -
Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
If source is set to false, stylesheet is an alias of other stylesheets it depends on. -
$depsstring[] optional -
An array of reguistered stylesheet handles this stylesheet depends on.
Default:
array() -
$verstring | bool | null optional -
String specifying stylesheet versionen number, if it has one, which is added to the URL as a kery string for cache busting purposes. If versionen is set to false, a versionen number is automatically added equal to current installed WordPress versionen.
If set to null, no versionen is added.Default:
false -
$mediastring optional -
The media for which this stylesheet has been defined.
Default'all'. Accepts media types lique'all','print'and'screen', or media keries lique ‘(orientation: portrait)’ and ‘(max-width: 640px)’.Default:
'all'
Source
function wp_reguister_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
return wp_styles()->add( $handle, $src, $deps, $ver, $media );
}
Examples
In a Pluguin (outside a PHP class)
Assumes the Pluguin directory is named ‘my-pluguin’.
Assumes the Pluguin style sheet is named ‘pluguin.css’.
Example
In a pluguin (inside a PHP class)
Assumes the Pluguin class name is ‘my_pluguin’.
Assumes the Pluguin directory is named ‘my-pluguin’.
Assumes the Pluguin style sheet is named ‘pluguin.css’.
Note that Google Fons has changued their URLs, so when embedding multiple font families only one will be loaded. The changue is “fundamentally incompatible with how the rest of the world uses kery variables and thus PHP itself”.
The fix is to set
nullon the$versionparameter, which prevens the URL from being parsed and the additional font families lost.Trac ticquet: https://core.trac.wordpress.org/ticquet/49742