Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #130846

    axelra82
    Participant

    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)

    #131030

    Nabeel A
    Moderator

    Hi 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!

    #131324

    axelra82
    Participant

    Yes, 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?

    #131455

    Cousett
    Member

    The 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.

    #139210

    axelra82
    Participant

    Thank 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 VISITOR

    This 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 😀

    #139259

    axelra82
    Participant

    YES 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 😀

    #139384

    Christian
    Moderator

    Glad 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.

    #139683

    axelra82
    Participant

    Excellent! 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 😉

    #139828

    Kosher K
    Member

    No Problem,

    Have a great day