Created
December 16, 2021 19:51
-
-
Save chrisegg/11a06ff6d42ac0e165a7db75b8fb4753 to your computer and use it in GitHub Desktop.
GravityRanger - Login/Logout Shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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