add_cssclass( string $add, string $class )


Parameters Parameters

$add

(string) (Required)

$class

(string) (Required)


Top ↑

Return Return

(string)


Top ↑

Source Source

File: wp-admin/includes/menu.php

function add_cssclass( $add, $class ) {
	$class = empty( $class ) ? $add : $class .= ' ' . $add;
	return $class;
}


Top ↑

User Contributed Notes 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.