Support » Everything else WordPress » Logout with hidden URL for Menu. Is it possible with CLASSES?

  • Resolved gabrieluno


    I need help to create a Logout Function for the top menu, it must hide the Url that would be “wp-login.php” and point to home.

    I suppose it could be done using a class that loads a function from wp_logout, so through the class I could load the function from the WordPress menu, and it would disconnect the user when clicking on the Logout button.

    The problem is that I have been searching the internet for days and there is no function to disconnect a user hiding the url through a class, I am also a newbie and I can not achieve it with incomplete codes. If someone is able to create a function that solves this problem, I will be grateful with all my heart, with such a feat your NAME will be remembered over time ♥

    Probably useful functions:
    Pastebin here

    • This topic was modified 8 months ago by gabrieluno.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Nigel M Rodgers


    The following function works for me:

    function wpa_redirect_item( $items, $menu, $args ) {
        foreach ( $items as $key => $item ) {
            if ( 'Logout' == $item->title ) {
                $items[$key]->url = wp_logout_url('/whatever-you-want');
        return $items;
    add_filter( 'wp_get_nav_menu_items', 'wpa_redirect_item', 10, 3 );

    change the slug inside wp_logout_url() to whatever link you want, or use ‘/’ for home.

    Edit: You need to have a menu item named “Logout”

    Thread Starter gabrieluno


    @rodgersnigel Thank you very much for your help, the logout is already working therefore the debate is resolved. Blessings

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Logout with hidden URL for Menu. Is it possible with CLASSES?’ is closed to new replies.