content top
Automatically add a search bar and login function to the wp-nav menu

Automatically add a search bar and login function to the wp-nav menu

Menu set ups have always been a pain in any theme configuration, but as WordPress has developed it has slowly become easier.

And with the latest release [WordPress 3.1], it has all become a whole lot easier again.

Simply add the following two pieces of code to your functions.php file:

To add Search…

[php]
add_filter(‘wp_nav_menu_items’,’add_search_box’, 10, 2);
function add_search_box($items, $args) {

ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();

$items .= ‘<li>’ . $searchform . ‘</li>’;

return $items;
}
[/php]

To add Login…

[php]
add_filter(‘wp_nav_menu_items’, ‘add_login_logout_link’, 10, 2);
function add_login_logout_link($items, $args) {
 
        ob_start();
        wp_loginout(‘index.php’);
        $loginoutlink = ob_get_contents();
        ob_end_clean();
 
        $items .= ‘<li>’. $loginoutlink generique viagra france.'</li>’;
 
    return $items;

}
[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *