I'm trying to add a custom menu item on my website. its showing perfectly but i need to show reverse order format.
It is like this screenshot:
add_filter('wp_nav_menu_items','add_custom_in_menu', 10, 2);
function add_custom_in_menu( $items, $args ) {
if( $args->theme_location == 'primary') {
$items .= "<li>
<div class='userView'> <img class='background' src='".get_bloginfo('template_url')."/assets/images/sidenav-logo-bg.png'> <a href='.'><img src='".get_bloginfo('template_url')."/assets/images/logo-mdm.png' class='responsive-img'></a> </div>
<div class='show-on-med-and-down nav-social'>
<a href='#' target='_blank' class='facebook'><i class='fa fa-facebook'></i></a>
<a href='#' target='_blank' class='twitter'><i class='fa fa-twitter'></i></a>
<a href='#' target='_blank' class='google'><i class='fa fa-google-plus'></i></a>
<a href='#' target='_blank' class='linkdin'><i class='fa fa-linkedin'></i></a>
<a href='#' class='email'><i class='fa fa-envelope'></i></a>
</div>
</li>";
}
return $items;
}
Menu linking code on header
<?php if ( has_nav_menu( 'primary' ) ) : ?>
<ul id="slide-out" class="side-nav">
<?php
// navigation menu.
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'orderby' => 'menu_order') );
?>
</ul>
<?php endif; ?>
I need reverse order like logo should be on top and others are looping below logo. Please help.
Currently you append logo (all the stuff inside <li>
) to $items
string. What you should instead is prepend it, like this:
if( $args->theme_location == 'primary') {
$items = "<li>\\ template is skipped for readability \\</li>" . $items;
}
return $items;
You might consider extracting logo template generation into a separate function.