Created
July 15, 2016 22:57
-
-
Save briankompanee/3b4a4c751c886ba9855fd44c6b2d905a to your computer and use it in GitHub Desktop.
WordPress: Add a shortcode to use in the content that shows content to non-logged in users. If user is logged in then they will not see the content.
This file contains hidden or 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 | |
/** | |
* Add A Shortcode allowing content for non-logged in users. | |
* Add to functions.php | |
* This could used in a situation where you have gated content and the user needs to be logged in to view. | |
* An example of usage is: [not_logged_in]You must be logged in to view this content[/not_logged_in] | |
*/ | |
function check_user ($params, $content = null){ | |
//if the user is not logged in. You can remove the ! if you want to change the statement to is logged in. | |
if ( !is_user_logged_in() ){ | |
return $content; | |
} | |
else{ | |
return; | |
} | |
} | |
add_shortcode('not_logged_in', 'check_user' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment