896 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
+4 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>
896 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
+4 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?

172 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
+5 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

172 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
+5 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!

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by