Mobile-Menu iFuturz Infoweb Inc. Contact Portfolio

01

Jul

Display Shortcode content to logged in users only in wordpress

Display Shortcode content to logged in users only in wordpress

Posted On : July 1, 2013

| No Comment

Ever wanted to be able to show some content only to logged in users in your blog posts?
If yes, just add below code in your shortcode function

1
 if(!is_user_logged_in()){ return ""; }

For example:

1
2
3
4
5
6
7
8
9
10
11
[logged-user-content]This text will be only displayed to login users[/logged-user-content]
 
add_shortcode( 'logged-user-content', 'logged_user_shortcode_function' );
 
function logged_user_shortcode_function($attr,$content=null){
 
if(!is_user_logged_in()){ return ""; }
 
return $content;
 
}
  • Tags:

Comment