WP_Theme_JSON::append_to_selector( string $selector, string $to_append ): string

In this article

Appends a sub-selector to an existing one.

Description

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

Parameters

$selectorstringrequired
Original selector.
$to_appendstringrequired
Selector to append.

Return

string The new selector.

Source

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

Changelog

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

User Contributed Notes

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