Jump to content
Sign in to follow this  

WordPress menu modifications

Recommended Posts

Hey all. I'm fairly new to WordPress (not php) and am running into an issue. I need to add link descriptions to 1 of 5 menus on my page. I've read about extending Walker_Nav_Menu() and am attempting that, and it's kinda going well except for one slightly annoying issue - it's returning the wrong menu.


I'm attempting to isolate the action to a menu with the slug 'subbrand-menu'. All the code follows:



$fn = new MyDev\FunctionClass();


namespace MyDev;
class FunctionClass{
        private    $_walker;
	public function buildSubbrandMenu($menu, $args){
		if(\is_admin() || $args->slug !== 'subbrand-menu'){
			return $menu;
			$this->_walker = new MyWalker;
			'menu'			=> 'subbrand_menu',
			'container'		=> 'div',
			'container_class'	=> 'menu-subbrand-menu-container',
			'container_id'		=> '',
			'menu_class'		=> 'menu',
			'menu_id'		=> 'menu-subbrand-menu',
			'echo'			=> true,
			'walker'		=> $this->_walker


namespace MyDev;
class MyWalker extends \Walker_Nav_Menu{
	public function end_el(&$output, $item, $depth=0, $args=array()) {
		$output .= "<span class='thisisadescr'>Testing, testing</span></li>";

Now, the above actually works quite well except that it's outputting the contents of a menu with the slug 'floater'.


Anybody have any ideas what I'm missing here? I'm sure it's something simple but it's driving me crazy right now. Thanks in advance for any and all thoughts, hints, tips, and ideas.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.