Support » Themes and Templates » wp_page_menu different classes

  • Resolved joshrodgers


    I am using the wp_page_menu funtion in my WordPress theme to display a site’s page menus. The code looks like:

    The code works great…but what I wanted to do was set a class and id (for implementing menus) on the ul tag, the wp_page_menu function doesn’t let you do that, but I did find some code that I added to my functions.php file which looks like:

    This function works, however I am using wp_page_menu in two places and I only want the functions code to be added to the first instance of wp_page_menu. I did some searching and found this piece of code:

    I tweaked the code (, but regardless of where I add it in my function, it doesn’t seem to do anything.

    Is the code correct? If so, did I incorrectly tweak the code? If not, where should the line be added for the code to work properly?

    Any ideas?


Viewing 2 replies - 1 through 2 (of 2 total)
  • its added by the filter, so the way you try wont work.

    Thank you Navaratnam, you were right! Because the code was being added by a filter, it was applying the code to every instance of the wp_page_menu function, instead of the specific instance I had intended.

    To solve this, I took the code from my functions file ( and deleted it completely, eliminating the filters I set on the wp_page_menu function.

    Then I took my existing code ( and added the preg_replace to the last line.

    So, now my code looks like this: The only thing that changed was line 14 of the code.

    So, all I do, is apply the code to the instance or instances of the wp_page_menu function that I need to change and presto! The change only gets made to the instance or instances I specify 🙂

    Hopefully this helps some out there!


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_page_menu different classes’ is closed to new replies.