-
AuthorPosts
-
October 23, 2014 at 11:29 am #130846
Hi.
I was wondering where the php file(s) for the menu are? I’m trying to find where the menu items are generated. I need to add the title as a visible sub-title for the main menu items. I know how, but I can’t find the correct files to update. I’ve been looking in both the views and functions folder, but I can’t find the correct file(s)/line(s)
October 23, 2014 at 3:22 pm #131030Hi Axelra,
Before editing the core files, please setup the child theme. Path for navbar is x/framework/views/global/_nav-primary.php
Let us know if you need any assistance!
October 24, 2014 at 4:38 am #131324Yes, thank you. I have a child theme setup. But I still can’t find what/where to change the php generated li items for the menu?
In the _nav-primary.php I need to know how this
elseif ( has_nav_menu( 'primary' ) ) : wp_nav_menu( array( 'theme_location' => 'primary', 'container' => false, 'menu_class' => 'x-nav sf-menu', ) );
translates into the actual li items presented on the client side.
Wheat I need to do is use the title (if present) for the menu item and present it as a visible “sub-title” for the menu item. But to do this I need to know what line, in what file the li element of the ul list that is the menu, is generated. Is it done in JS or PHP?
October 24, 2014 at 8:50 am #131455The menu is getting formed from the array of menu items in the above elseif you reference. It is done in the PHP from what is entered into the menu settings.
November 5, 2014 at 3:49 pm #139210Thank you for your answer… maybe its just me being unclear. But I would very much like to know how I can display the title (if present) as a “sub text” to the actual menu item.
So
MENU ITEM (title in value. Present but not visible, unless visitor hovers item)– becomes –
MENU ITEM
—
subtext <—- THIS IS VISIBLE TO VISITORThis is what I want to achieve. I’ve done this before… But I can’t find where on gods green earth the actual li element is being rendered haha 🙂
I can only get to the array… then what? Where is the li created with PHP? Please explain to me how the menu is rendered 😀November 5, 2014 at 5:22 pm #139259YES YES YES! haha, I finally found how to achieve this… Sadly it involves editing core files… But I don’t know of any other way. Hopefully a simple “show/hide” description option will be added in future release? 😉
I added the following (see bellow) to the file _ROOT/wp-includes/nav-menu-template.php around line line 154
if(!empty($item->description)){ $subDesc = '<br /><span class="subText">' . $item->description . '</span>'; }
So, if there is a description (kinda’ the whole point of this exercise haha), put it all in a variable called subDesc and create a line break then add a span class with the description inside it. Then at
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
a couple of lines bellow. Add, “. $subDesc” (without quotations) at the end (like so)
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after . $subDesc;
and you’re all set 😉I know all code ninjas here understand all of this, but since it took me a couple of days of searching to figure this out I thought it would be nice for anyone else, who wasn’t a code ninja, to get a “clearer” explanation on how to achieve this 😀
November 5, 2014 at 10:58 pm #139384Glad you’ve found a solution Axel. X does not support menu description so adding it falls beyond the scope of our support. We’ll take note of this as feature request and might implement it in a future release.
I’d just like to add that you don’t have to hack the core files to achieve that. Please see this tutorial http://www.wpbeginner.com/wp-themes/how-to-add-menu-descriptions-in-your-wordpress-themes/ on how to properly implement that.
Thanks.
November 6, 2014 at 10:29 am #139683Excellent! Thank you for that tutorial. That did the trick, without hacking core files (which of course is always the preferred way to go when possible).
Yes, it would be a nice simple feature to have in the menu settings. Might not be the most sought after feature, but still something to be expected in my opinion 🙂
Thanks again for the “non-hackish” way of implementing this 😉
November 6, 2014 at 1:49 pm #139828No Problem,
Have a great day
-
AuthorPosts