/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
One of the problems of using wp_page_menu is that the HTML is all wrapped in the function. You can’t get at it. Which is a pain if you want to use the function but also want to add special classes for implementing javascript drop-down menus or do some trickier CSS without giving yourself a headache. Luckily, you can filter it. Here’s how to filter wp_page_menu and add a unique class to the first instance of the ul tag, using PHP’s preg_replace to find the first ul tag and adding in id and class attributes. // Add ID and CLASS attributes to the first <ul> occurence in wp_page_menu function add_menuclass($ulclass) { } add_filter('wp_page_menu','add_menuclass');