• I am using this function to make my navigation a dropdown list

    <nav class="page-name">
            <?php
                class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{
                    function start_lvl(&$output, $depth){
                        $indent = str_repeat("\t", $depth); // don't output children opening tag (<code><ul></code>)
                    }
    
                    function end_lvl(&$output, $depth){
                        $indent = str_repeat("\t", $depth); // don't output children closing tag
                    }
    
                    function start_el(&$output, $item, $depth, $args){ // add spacing to the title based on the depth
                        $item->title = $item->title;
    
                        parent::start_el(&$output, $item, $depth, $args);
    
                        // no point redefining this method too, we just replace the li tag...
                        $output = str_replace('<li', '<option', $output);
                    }
    
                    function end_el(&$output, $item, $depth){
                        $output .= "</option>\n"; // replace closing </li> with the option tag
                    }
                }
    
                wp_nav_menu(array(
                    'theme_location' => 'primary', // your theme location here
                    'walker'         => new Walker_Nav_Menu_Dropdown(),
                    'items_wrap'     => '<select>%3$s</select>',
                ));
            ?>
        </nav>

    But I cant use the pages names to navigate because they are unaware of the formatting of the links that can look like this: /?p=57
    How can I get the the href value that is generated in normal nav menu and put it as a value attribute of the <option> element?

    Also, how can I display current page name in the select box?

  • The topic ‘How can i get separate navigation links?’ is closed to new replies.