[resolved] wp_page_menu different classes (3 posts)

  1. joshrodgers
    Posted 3 years ago #

    I am using the wp_page_menu funtion in my WordPress theme to display a site's page menus. The code looks like: http://pastebin.com/9Sa6jTnG

    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: http://pastebin.com/2frXmyHL

    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: http://themeshaper.com/forums/topic/second-wp_page_menu-with-different-classes

    I tweaked the code (http://pastebin.com/GVU9wLT2), 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?


  2. Navaratnam
    Posted 3 years ago #

    its added by the filter, so the way you try wont work.

  3. joshrodgers
    Posted 3 years ago #

    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 (http://pastebin.com/2frXmyHL) and deleted it completely, eliminating the filters I set on the wp_page_menu function.

    Then I took my existing code (http://pastebin.com/9Sa6jTnG) and added the preg_replace to the last line.

    So, now my code looks like this: http://pastebin.com/qBtnaNr9. 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!


Topic Closed

This topic has been closed to new replies.

About this Topic