WP_Styles::_css_href
Generates an enqueued style's fully-qualified URL.
Method of the class: WP_Styles{}
Hooks from the method
Returns
String. Style's fully-qualified URL.
Usage
global $wp_styles; $wp_styles->_css_href( $src, $ver, $handle );
- $src(string) (required)
- The source of the enqueued style.
- $ver(string|false|null) (required)
- The version of the enqueued style.
- $handle(string) (required)
- The style's registered handle.
Changelog
| Since 2.6.0 | Introduced. |
WP_Styles::_css_href() WP Styles:: css href code WP 7.0
public function _css_href( $src, $ver, $handle ) {
if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && str_starts_with( $src, $this->content_url ) ) ) {
$src = $this->base_url . $src;
}
$ver_to_add = '';
if ( empty( $ver ) && null !== $ver && is_string( $this->default_version ) ) {
$ver_to_add = $this->default_version;
} elseif ( is_scalar( $ver ) ) {
$ver_to_add = (string) $ver;
}
$added_args = (string) ( $this->args[ $handle ] ?? '' );
if ( '' !== $ver_to_add || '' !== $added_args ) {
$fragment = strstr( $src, '#' );
if ( false !== $fragment ) {
$src = substr( $src, 0, -strlen( $fragment ) );
}
if ( '' !== $ver_to_add ) {
$src .= ( str_contains( $src, '?' ) ? '&' : '?' ) . 'ver=' . rawurlencode( $ver_to_add );
}
if ( '' !== $added_args ) {
$src .= ( str_contains( $src, '?' ) ? '&' : '?' ) . $added_args;
}
if ( false !== $fragment ) {
$src .= $fragment;
}
}
/**
* Filters an enqueued style's fully-qualified URL.
*
* @since 2.6.0
*
* @param string $src The source URL of the enqueued style.
* @param string $handle The style's registered handle.
*/
$src = apply_filters( 'style_loader_src', $src, $handle );
return esc_url( $src );
}