WP_Theme_JSON::append_to_selector()protected staticWP 5.8.0

Appends a sub-selector to an existing one.

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

Method of the class: WP_Theme_JSON{}

No Hooks.

Return

String. The new selector.

Usage

$result = WP_Theme_JSON::append_to_selector( $selector, $to_append );
$selector(string) (required)
Original selector.
$to_append(string) (required)
Selector to append.

Changelog

Since 5.8.0 Introduced.
Since 6.1.0 Added append position.
Since 6.3.0 Removed append position parameter.

WP_Theme_JSON::append_to_selector() code WP 6.5.3

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