WP_Theme_JSON::append_to_selector() WordPress Method

This function allows you to append a string to the theme's CSS selector. This is useful if you want to add extra CSS to the theme, but don't want to override the theme's existing styles.

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

Function that appends a sub-selector to a 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".


Top ↑

Parameters

$selector

(string)(Required)Original selector.

$to_append

(string)(Required)Selector to append.


Top ↑

Return

(string)


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

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

		return implode( ',', $new_selectors );
	}

Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.