17 posts
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in France
  • Has been part of the Envato Community for over 2 years

I’m making a mobile version of my site, the problem I’m facing is that the dropdown menu does not take me to my first page on the list. For example, I have set “Home” as the first item on my navbar, all the other pages will work but my navbar will not take me to the homepage. This is the code that I’m using:

class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{
 var $to_depth = -1;
   function start_lvl(&$output, $depth){
     $output .= '</option>';
   function end_lvl(&$output, $depth){
     $indent = str_repeat("\t", $depth); // don't output children closing tag
   function start_el(&$output, $item, $depth, $args){
   $indent = ( $depth ) ? str_repeat( " ", $depth * 4 ) : '';
   $class_names = $value = '';
   $classes = empty( $item->classes ) ? array() : (array) $item->classes;
   $classes[] = 'menu-item-' . $item->ID;
   $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item,  $args ) );
   $class_names = ' class="' . esc_attr( $class_names ) . '"';
   $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
   $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
   $value = ' value="'. $item->url .'"';
   $output .= '<option'.$id.$value.$class_names.'>';
   $item_output = $args->before;
   $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args- >link_after;
   $output .= $indent.$item_output;
   function end_el(&$output, $item, $depth){
   if(substr($output, -9) != '</option>')
         $output .= "</option>"; // replace closing  with the option tag

And this to call it:

<?php wp_nav_menu(array
('theme_location' => 'category-nav',
'walker' => new Walker_Nav_Menu_Dropdown(),
'items_wrap' => '<select id="sec-selector" name="sec-selector" onchange="location.href =    document.getElementById(\'sec-selector\').value;">%3$s</select>',
'container_id' => 'mobile_menu_secondary'));?>

Please help!

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes