Created
September 10, 2013 13:44
-
-
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
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
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