Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Adding Conditional Classes to Menu Items


/**
 * Filter the CSS class for a nav menu based on a condition.
 *
 * @param array  $classes The CSS classes that are applied to the menu item's <li> element.
 * @param object $item    The current menu item.
 * @return array (maybe) modified nav menu class.
 */
function wpdocs_special_nav_class( $classes, $item ) {
    if ( is_single() && 'Blog' == $item->title ) {
        // Notice you can change the conditional from is_single() and $item->title
        $classes[] = "special-class";
    }
    return $classes;
}
add_filter( 'nav_menu_css_class' , 'wpdocs_special_nav_class' , 10, 2 );
Comment

PREVIOUS NEXT
Code Example
Php :: php how to loop through array_rand 
Php :: get my account orders page url woocommerce 
Php :: sorting table row data with php 
Php :: php thorwable vs exception 
Php :: Script to create AdminLTE in a Laravel project 
Php :: laravel how to fetch user from user model based on id from post 
Php :: PHP strpbrk — Search a string for any of a set of characters 
Php :: bring up the power shell console php 
Php :: how to use php variable in javascript file 
Php :: Composer detected issues in your platform: Your Composer dependencies require a PHP version "= 7.4.0". 
Php :: laravel upsert always inserting 
Php :: How to return custom error message from controller method validation 
Php :: King Composer Theme Export 
Php :: php loop array PDO remove keys 
Php :: PHP vsprintf — Return a formatted string 
Php :: laravel validation error messages are not showing on register oage 
Php :: laravel get relation camelcase api 
Php :: laravel compile blade 
Php :: wordpress get posts by multiple authors 
Php :: undefine variable $variable in php 
Php :: Laravel Retrieving Session Data 
Php :: update php version of particular domain on ubuntu 
Php :: saber value ao escolher combobox php 
Php :: newrelic apache virtual hosts 
Php :: sub() vs substr in php 
Php :: Primary Termlaravel recursive relationships 
Php :: diferencias empty() e isset() 
Php :: php The function is a conversion from a key to a value 
Php :: larave per page int returns string 
Php :: Return back to a specific html element - Laravel 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =