508 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

I know I need to use the function for what I want to do, but I have very little exposure to it so need some help.

On the wordpress menu system (wp 3.0+), they add a hell of a lot of extra code which I don’t need.

I have worked out how to replace the divs, and the ul around the menu, but the li has a load of classes and an id which I don’t need / want.

Below is the code I have used to try and remove the code, but not having any luck

function add_menuclass($liclass) {
 return preg_replace( array( '#^<li class="menu-item menu-item-type-post_type"[^>]*>#' ), '<li>', $menu );
}
add_filter('wp_page_menu','add_menuclass');
</li>
508 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

bump, anyone know what I am doing wrong?

238 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
ewizz says

bump, anyone know what I am doing wrong?

160 posts
  • Power Elite Author
  • Power Elite Author: Sold between 1 000 000 - 1 999 999 dollars
  • Exclusive Author
  • Has been a member for 5-6 years
  • Bought between 100 and 499 items
  • Referred between 500 and 999 users
stmcan says

Hi Gareth,

I guess you must change the $menu with $liclass

 
function add_menuclass($liclass) {
 return preg_replace( array( '#^<li class="menu-item menu-item-type-post_type"[^>]*>#' ), '<li>', $liclass );
}
add_filter('wp_page_menu','add_menuclass');
</li>

hope it helps.

Tolga

238 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
ewizz says

not really.

he was talking about wp 3.0+ menu, which means wp_nav_menu not wp_page_menu

for wp_nav_menu you need to write walker (extend it) so you get rid of that extra code

160 posts
  • Power Elite Author
  • Power Elite Author: Sold between 1 000 000 - 1 999 999 dollars
  • Exclusive Author
  • Has been a member for 5-6 years
  • Bought between 100 and 499 items
  • Referred between 500 and 999 users
stmcan says

yeah, you’re right! i didn’t see the wp_page_menu. But i’ve used add_filter without walker, it works!

by
by
by
by
by
by