Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2021 19:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
GravityRanger - Login/Logout Shortcode
//copy everything below this line
* GravityRanger Login Logout Shortcode
* Creates a login/logout shortcode button
* Used for creating a login/logout shortcode to be used with a WordPress website.
* Can be a great supliment feature when using Gravity Forms to build membership sites.
* @instructions:
* 1. Set the logout and login URL - change /url-slug-here to any URL slug you'd like
* 2. Add this code snippet to your functions.php file or a functionality plugin like WPCodeBox
* 3. Use the [login_logout] shortcpde to create your button (place it anywhere on your site, i.e nav, header, footer, widget, etc)
* @version 0.1
* @author GravityRanger
* @license GPL-2.0+
* @link
add_shortcode( 'login_logout', 'login_logout' );
function login_logout() {
if (is_user_logged_in()) :
<a role="button" href="<?php echo wp_logout_url('/url-slug-here'); ?>">Log Out</a>
else :
<a role="button" href="<?php echo wp_login_url('/url-slug-here'); ?>">Log In</span></a>
return ob_get_clean();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment