WP_Theme_JSON::prepend_to_selector()protected staticWP 6.3.0

Prepends a sub-selector to an existing one.

Given the compounded $selector "h1, h2, h3" and the $to_prepend selector ".some-class " the result will be ".some-class h1, .some-class h2, .some-class h3".

Method of the class: WP_Theme_JSON{}

No Hooks.

Return

String. The new selector.

Usage

$result = WP_Theme_JSON::prepend_to_selector( $selector, $to_prepend );
$selector(string) (required)
Original selector.
$to_prepend(string) (required)
Selector to prepend.

Changelog

Since 6.3.0 Introduced.

WP_Theme_JSON::prepend_to_selector() code WP 6.6.2

protected static function prepend_to_selector( $selector, $to_prepend ) {
	if ( ! str_contains( $selector, ',' ) ) {
		return $to_prepend . $selector;
	}
	$new_selectors = array();
	$selectors     = explode( ',', $selector );
	foreach ( $selectors as $sel ) {
		$new_selectors[] = $to_prepend . $sel;
	}
	return implode( ',', $new_selectors );
}