• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

Add a Custom Class & Style Specific WP Nav Menu Items Conditionally

I found this code on the WordPress Codex recently which i think will be useful.

The code enables you to generate custom classes for specific menu items conditionally.

This way you can use CSS code to change the appearance of each item using conditional tags.

add_filter('nav_menu_css_class' , 'conditional_nav_menu_class' , 10 , 2);
function conditional_nav_menu_class($classes, $item){
if ( is_front_page() AND $item->title == "Home") { 
             $classes[] = "home-icon";
     }
     return $classes;
}

Source http://codex.wordpress.org/Function_Reference/wp_nav_menu

Nav Menu

Reader Interactions

Comments

  1. Hea figurether Hess says

    January 3, 2014 at 5:18 pm

    thanks Brad – I think I’ll give it a break for a few days and go for a walk and come back and it will all make sense.

    I am good at adding content to sites and networking but my mind can’t figure coding out very easily.

    Heather

    Log in to Reply
  2. scot says

    January 3, 2014 at 4:37 am

    Could you not repeat the code for other pages? If you know for sure the pages you will be using?

    Log in to Reply
    • Brad Dalton says

      January 3, 2014 at 10:10 am

      That’s right Scot.

      Log in to Reply
  3. Heather Hess says

    January 2, 2014 at 8:28 pm

    thanks Brad – my mind is going crazy with all this coding – I will try and figure it out. However, I would like to get someone to help me so I can network and add content – my two main talents.

    Heather

    Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags