Programmatically Add login and logout Item in Menu

add_filter( 'wp_nav_menu_items', 'add_logout_link', 10, 2);

 * Add a login link to the members navigation
function add_logout_link( $items, $args )
    if($args->theme_location == 'main-menu')
            $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
        } else {
            $items .= '<li><a href="'. wp_login_url() .'">Log In</a></li>';

    return $items;

Note: Need to change theme location main-menu by using your menu id.

The following two tabs change content below.

Md Jahed

Latest posts by Md Jahed (see all)

Leave a Reply

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