Skip to content

WordPress First & Last Navigation Items

I used to have a function which I would include in my WordPress functions.php file that would add a unique CSS class to the first and last menu items. This would be so you could assign them unique styles, such as padding or borders, for better looking menus in your themes.

With the advent of WordPress’s Menu system in version 3, I found it necessary to add some more functions for given situations: calling wp_list_pages(), wp_list_categories(), or wp_nav_menu().  So here they are:

First and Last Class for wp_list_pages();

First and Last Class for wp_list_categories();

First and Last Class for wp_nav_menu();

Disclaimer: I don’t remember where I picked up these functions from along the way, so I apologize if there is credit due to someone, somewhere.

Published inWordPress

2 Comments

  1. Katy Katy

    Thank you thank you thank you, this was clean, easy and allowed me to do what I wanted in about 30 seconds. Appreciated 🙂

    • Glad it helped! That’s what I do this for.

Leave a Reply

%d bloggers like this: