WordPress.org

Ready to get started?Download WordPress

Forums

How do I make a custom item as a submenu in my themes functions file? (1 post)

  1. x0fx3
    Member
    Posted 2 years ago #

    I added this to my themes fuctions file

    Added login/out link to the menu:

    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 .'</li>';
    
        return $items;
    }

    But I want this to be a sub item of the login/out menu item. This code adds a register/site admin link to the menu after the login/out menu item.

    add_filter('wp_nav_menu_items', 'add_register_link', 10, 2);
    function add_register_link($items, $args) {
    
            ob_start();
            wp_register('');
            $registerlink = ob_get_contents();
            ob_end_clean();
            $items .= '<li>'. $registerlink .'</li>';
        return $items;
    }

    I don't know php so I found these on other sites. But not sure how to make the register/site admin code a submenu to the login.

    Any help would be greatly appreciated.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic