Skip to content

Instantly share code, notes, and snippets.

@rushijagani
Created April 25, 2018 12:33
Show Gist options
  • Save rushijagani/1fd0a59e47603a24787ea55f78d11369 to your computer and use it in GitHub Desktop.
Save rushijagani/1fd0a59e47603a24787ea55f78d11369 to your computer and use it in GitHub Desktop.
Menu Description Filter
<?php
// Add below filter to display Menu Descripiton in child theme's functions.php file.
function prefix_nav_description( $item_output, $item, $depth, $args ) {
if ( !empty( $item->description ) ) {
$item_output = str_replace( $args->link_after . '</a>', '<span class="menu-item-description">' . $item->description . '</span>' . $args->link_after . '</a>', $item_output );
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'prefix_nav_description', 10, 4 );
@rushijagani
Copy link
Author

rushijagani commented Apr 25, 2018

Add below CSS to make Menu Description style compatible with Astra Theme.

.main-header-menu {
    text-align: left;
}
.menu-item-description{
    display: block;
    font-weight: normal;
    line-height: 1.2;
}
.main-header-bar .main-navigation > ul > li.page_item_has_children > a:before, .main-header-bar .main-navigation > ul > li.menu-item-has-children > a:before{
    position: absolute;
    right: 0;
    top: calc( 50% - 3px);
    content: "\e900";
    display: inline-block;
    font-family: 'Astra';
    font-size: 9px;
    font-size: .6rem;
    font-weight: bold;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin-left: 10px;
    vertical-align: middle;
    line-height: normal;
}
.main-header-bar .main-navigation > ul > li.page_item_has_children > a:after, .main-header-bar .main-navigation > ul > li.menu-item-has-children > a:after{
    display:none;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment