I am writing a simple WP plugin that could log the user in and out. As far as login is concerned its working good but I cannot log out, through my plugin. Logout doesn't work after I login. I have tried a lot of suggested solutions but none of them worked.

This is my code:

function vrm_loginout(){


        echo '<a href="<?php echo wp_logout_url($redirect); ?>" title="Logout">Logout</a>';

        //tried following as well
    //echo '<a href="<?php echo wp_logout_url( get_permalink() )>" title="Logout">Logout</    a>'; title="Logout">Logout</a>';



    }//end of if

}//end of function

add_shortcode('vrm_loginform', 'vrm_loginout');

You are using PHP tag inside echo statement.

Try this:

echo '<a href="'.wp_logout_url().'" title="Logout">Logout</a>';

If you want to redirect to any specific url then you can pass it as argument of wp_logout_url.

Check official documentation of wp_logout_url.

Note :

It is recommended to return value from the shortcode function rather than directly displaying it. Try return instead of printing output by echo.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.