Adding Descriptions To Nav Items

Hello: I’m trying to add descriptions to my nav items and am following an older post (https://theme.co/apex/forums/topic/customizing-the-menu/). I understand this is out of scope, but my questions are:

  1. around using the /framework/cranium/headers/functions/navbar.php file. When I copy this same path to my child theme and try modifying the menu_class, nothing happens. I can only edit the parent theme file to actually change this. Is there another dependency file that reads this over the parent theme? I can echo a basic statement out on /_nav-primary, but I’m not able to get this working.

  2. in the same path above, I’m trying to add walker to the array from the instructions (https://www.wpbeginner.com/wp-themes/how-to-add-menu-descriptions-in-your-wordpress-themes/). This also does not work. I’m assuming this is the issue I’m having with #1, but wanted to get your thoughts on why it’s happening or what can be done to fix it.

Thanks!

Hello @quincyadam,

Thanks for asking. :slight_smile:

File that you are editing under /wp-content/themes/x/framework/legacy/cranium/headers/views/global/_nav-primary.php is correct one. I would suggest you to check again the child theme folder structure path and make sure that the folders are created under the same order. For some more additional information, please take a look at following resources.

Thanks.

Hi Prasant,

Thanks for the quick reply. I can make the change in that file path in my child theme. It’s the navbar.php file located: /framework/cranium/headers/functions/navbar.php. I’m not having luck making a change in this file on my child theme and the path is identical. I can, however, make the change in the parent theme path. What I’m specifically trying to do is add: ‘walker’ => $walker to the wp_nav_menu array if you have another suggested method.

Thanks.

Hi Prasant,

Just to clarify further, I can modify the navbar.php file in the parent x theme and modify:

} elseif ( has_nav_menu( ‘primary’ ) ) {

$walker = new Menu_With_Description;
    
  wp_nav_menu( array(
    'theme_location' => 'primary',
    'container'      => false,
    'walker'         => $walker,   
    'menu_class'     => 'x-nav newClassName',
    'link_before'    => '<span>',
    'link_after'     => '</span>'
  ) );

But if I modify the same file/same path (/framework/cranium/headers/functions/navbar.php) in my child theme, it doesn’t work. Modifying other files works fine. Let me know if this makes sense.

Thanks.

Hey @quincyadam.

Files under the functions folder like /functions/navbar.php and they should be overridden by copying the function to your child theme’s functions.php.

For example, you want to override the One Page Navigation function, you copy the function enclosed in the screenshot below to your child theme’s functions.php

Hope that helps.

Hi Christian, unfortunately it doesn’t. I’m applying the same change I made from the parent theme to child, and it doesn’t work.

Changing this works:
x/framework/cranium/headers/functions/navbar.php

Changing this does not:
childtheme/framework/cranium/headers/functions/navbar.php

I also have the show current template plugin installed and it doesn’t appear to be loading the navbar.php file from the child theme. Also, to be clear, if I modify other files, the child theme does work; just not this file.

Hi There,

Christian meant you just need to copy the function NOT the file contains functions.

For example, copy the x_get_one_page_navigation_menu() to the functions.php file locates in your child theme:

  function x_is_one_page_navigation() {

    $one_page_navigation = x_get_one_page_navigation_menu();

    if ( $one_page_navigation == 'Deactivated' ) {
      $output = false;
    } else {
      $output = true;
    }

    return $output;

  }

For more information, please take a look at this:

Hope it helps :slight_smile:

Hi Christian and Thai,

WP Engine’s support ran into the same issue. They said:

My only guess would be to see if moving the file would allow the other one to be read. Perhaps there might be an action or hook that you can try to add to force the child themes file, but that’s more on the development side of things. If the theme developer did not recommend it, then it might not be needed.

I attempted your suggestion to only copy the function attached at the same path and it did not work.

Thanks!

Hi There,

Could you please paste this code under functions.php file locates in your child theme directory?

function x_output_primary_navigation() {

    if ( x_is_one_page_navigation() ) {

      wp_nav_menu( array(
        'menu'           => x_get_one_page_navigation_menu(),
        'theme_location' => 'primary',
        'container'      => false,
        'menu_class'     => 'x-nav x-nav-scrollspy',
        'link_before'    => '<span>',
        'link_after'     => '</span>'
      ) );

    } elseif ( has_nav_menu( 'primary' ) ) {
      $walker = new Menu_With_Description;
      wp_nav_menu( array(
        'theme_location' => 'primary',
        'container'      => false,
        'menu_class'     => 'x-nav',
        'walker' => $walker,
        'link_before'    => '<span>',
        'link_after'     => '</span>'
      ) );

    } else {

      echo '<ul class="x-nav"><li><a href="' . home_url( '/' ) . 'wp-admin/nav-menus.php">Assign a Menu</a></li></ul>';

    }

}

If it doesn’t help, would you mind providing us with login credentials(by clicking on the Secure Note button at the bottom) so we can take a closer look? To do this, you can make a post with the following info:

  • Link to your site
  • WordPress Admin username / password

Thanks.

Hi Thai,

This worked! I’m not sure why it didn’t work from the other path, but this is good enough for me.

Thanks!

We are delighted to assist you with this.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.