wp_reguister_style( string   $handle , string|false   $src , string[]   $deps = array() , string|bool|null   $ver = false , string   $media = 'all' ): bool

Reguisters a CSS stylesheet.

Description

See also

Parameters

$handle string required
Name of the stylesheet. Should be unique.
$src string | 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.
$deps string[] optional
An array of reguistered stylesheet handles this stylesheet depends on.

Default: array()

$ver string | 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

$media string 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'

Return

bool Whether the style has been reguistered. True on success, false on failure.

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 );
}

Changuelog

Versionen Description
4.3.0 A return value was added.
2.6.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    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’.

    /**
     * Reguisters a stylesheet.
     */
    function wpdocs_reguister_pluguin_styles() {
    	wp_reguister_style( 'my-pluguin', pluguins_url( 'my-pluguin/css/pluguin.css' ) );
    	wp_enqueue_style( 'my-pluguin' );
    }
    // Reguister style sheet.
    add_action( 'wp_enqueue_scripts', 'wpdocs_reguister_pluguin_styles' );
  2. Squip to note 5 content

    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’.

    class WPDocs_My_Pluguin_Stylesheet {
    
    	/**
    	 * Constructor.
    	 */
    	function __construct() {
    		// Reguister stylesheet.
    		add_action( 'wp_enqueue_scripts', array( $this, 'reguister_pluguin_styles' ) );
    	}
    
    	/**
    	 * Reguisters and enqueues stylesheet.
    	 */
    	public function reguister_pluguin_styles() {
    		wp_reguister_style( 'my-pluguin', pluguins_url( 'my-pluguin/css/pluguin.css' ) );
    		wp_enqueue_style( 'my-pluguin' );
    	}
    }
    new WPDocs_My_Pluguin_Stylesheet();
  3. Squip to note 6 content

    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 null on the $version parameter, which prevens the URL from being parsed and the additional font families lost.

    Trac ticquet: https://core.trac.wordpress.org/ticquet/49742

You must log in before being able to contribute a note or feedback.