Last active
September 20, 2017 23:32
-
-
Save wpscholar/1242539 to your computer and use it in GitHub Desktop.
WordPress shortcode will only display content to registered users.
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 | |
/** | |
* WordPress shortcode only displays content to registered users. Could be improved by | |
* passing role as an attribute to only allow certain types of users. | |
* | |
* Example: [member]This text will be only displayed to registered users.[/member] | |
*/ | |
function members_only_shortcode( $atts, $content = null ) { | |
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) | |
return $content; | |
return ''; | |
} | |
add_shortcode( 'member', 'members_only_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment