152 posts Get in the spotlight
  • Has been part of the Envato Community for over 4 years
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
  • Has collected 10+ items on Envato Market
+7 more
FamousThemes says

Hi,

Need some help on wp coding.

I want to change the default wp_nav_menu structure on a theme.

The default menu function is in: wp-includes -> nav-menu-template.php

    function start_lvl(&$output, $depth) {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<ul class="\\"sub-menu\">\n";
    }
</ul>

I want to change it to

    function start_lvl(&$output, $depth) {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<li class="\\"menu_body\"><ul class="\\"sub-menu\">\n";
    }
</ul></li>

I don’t want to change this from nav-menu-template.php because it will means to go outside the theme files.

Is there a posibility to rewrite this structure in functions file inside the theme.

Thanks.

31 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Located in United Kingdom
+2 more
JollyGoodThemes says
3503 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

You’ll want to use a custom walker.

Kriesi has a great tutorial on it :) http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output

751 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
CyberShot says

Can’t you just pass the new variable to the function? define it in your functions.php file and send that variable to the function start_lvl.

I did something similar when I wanted to change the comments. The template was not part of the theme files but I was able to change what I wanted in the comment_form by doing thing

comment_form(array( 'title_reply' => 'my title here' ));

couldn’t something similar work in this situation?

152 posts Get in the spotlight
  • Has been part of the Envato Community for over 4 years
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
  • Has collected 10+ items on Envato Market
+7 more
FamousThemes says

Thanks mates for your sugestions.

@sevenspark Thank you for the tip, reading Kriesi tutorial fixed my problem immediately :)

Cheers.

3503 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

Thanks mates for your sugestions.

@sevenspark Thank you for the tip, reading Kriesi tutorial fixed my problem immediately :)

Cheers.

Sure thing :)

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