add_cssclass( string $class_to_add, string $classes )

Adds a CSS class to a string.


Parameters

$class_to_add

(string) (Required) The CSS class to add.

$classes

(string) (Required) The string to add the CSS class to.


Top ↑

Return

(string) The string with the CSS class added.


Top ↑

Source

File: wp-admin/includes/menu.php

function add_cssclass( $class_to_add, $classes ) {
	if ( empty( $classes ) ) {
		return $class_to_add;
	}

	return $classes . ' ' . $class_to_add;
}


Top ↑

Changelog

Changelog
Version Description
2.7.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by MakeWebBetter

    Usage when working over menus order

    $firstm = $lastm = false;
    $i = 0;
    
    foreach ( $menu as $order => $top ) {
            $i++;
    
            if ( 0 == $order ) {
                $menu[0][4] = add_cssclass( 'menu-top-first', $top[4] );
                $lastm = 0;
                continue;
            }
    
            if ( 0 === strpos( $top[2], 'separator' ) && false !== $lastm ) {
                // if separator
                $firstm = true;
                $c = $menu[ $lastm ][4];
                $menu[ $lastm ][4] = add_cssclass( 'menu-top-last', $c );
                continue;
            }
    
            if ( $first ) {
                $c = $menu[ $order ][4];
                $menu[ $order ][4] = add_cssclass( 'menu-top-first', $c );
                $firstm = false;
            }
    
            $lastm = $order;
        }
    

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