Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GravityRanger - Login/Logout Shortcode
<?php
//copy everything below this line
/**
* GravityRanger Login Logout Shortcode
*
* Creates a login/logout shortcode button
* https://gravityranger.com/login-logout-shortcode-for-gravity-forms-membership-sites/
*
* 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 http://gravityranger.com/
*
*
*/
add_shortcode( 'login_logout', 'login_logout' );
function login_logout() {
ob_start();
if (is_user_logged_in()) :
?>
<a role="button" href="<?php echo wp_logout_url('/url-slug-here'); ?>">Log Out</a>
<?php
else :
?>
<a role="button" href="<?php echo wp_login_url('/url-slug-here'); ?>">Log In</span></a>
<?php
endif;
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment