WP_Theme_JSON::append_to_selector() – Appends a sub-selector to an existing one.

You appear to be a bot. Output may be restricted

Description

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

Usage

$string = WP_Theme_JSON::append_to_selector( $selector, $to_append, $position );

Parameters

$selector
( string ) required – Original selector.
$to_append
( string ) required – Selector to append.
$position
( string ) optional default: right – A position sub-selector should be appended. Default 'right'.

Returns

string The new selector.

Source

File name: wordpress/wp-includes/class-wp-theme-json.php
Lines:

1 to 8 of 8
  protected static function append_to_selector( $selector, $to_append, $position = 'right' ) {
    $new_selectors = array();
    $selectors     = explode( ',', $selector );
    foreach ( $selectors as $sel ) {
      $new_selectors[] = 'right' === $position ? $sel . $to_append : $to_append . $sel;
    }
    return implode( ',', $new_selectors );
  }
 

 View on GitHub View on Trac