Skip to content

Instantly share code, notes, and snippets.

@dannyockilson
Created September 10, 2013 13:44
Show Gist options
  • Save dannyockilson/6509594 to your computer and use it in GitHub Desktop.
Save dannyockilson/6509594 to your computer and use it in GitHub Desktop.
Simple Wordpress Secured Content Shortcode: Add this to your functions.php to enable [is_logged_in]Members only content[/is_logged_in] and [not_logged_in]Non Members content[/not_logged_in] in posts/pages
function is_logged_in($atts, $content){
if(is_user_logged_in()){
return do_shortcode($content);
}
else {
// this is used incase you want to attach an icon/message to show more information is available on login
return "<span class='secured'></span>";
}
}
add_shortcode( 'is_logged_in' , is_logged_in );
// simple function with opposite functionality to above
function not_logged_in($atts, $content){
if(!is_user_logged_in()){
return do_shortcode($content);
}
else {
return "<span class='member'></span>";
}
}
add_shortcode( 'not_logged_in' , not_logged_in );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment