745 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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>
745 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
Gareth_Gillman says

bump, anyone know what I am doing wrong?

238 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
ewizz says

bump, anyone know what I am doing wrong?

170 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
+4 more
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
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
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

170 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
+4 more
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