Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Show Message to Logged In User with a Short Code

Posted on September 18, 2011 by Pippin in Intermediate, Plugins, Quick Tips, Short Codes, Tutorials, Video Tutorials 3 Comments
Home» Tutorials » Intermediate » Show Message to Logged In User with a Short Code
Tweet
Love It - 1

Being able to restrict certain content to logged in members only is a very useful function, especially for membership based websites, whether free or premium. This quick tutorial shows you the basics of how to write a short code function that will allow you to limit blocks of content to logged in users only.

Check out the video for an explanation of what is going on, or skip straight to the code.

The code needed to do this is pretty minimal:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function pippin_logged_in_user_shortcode($atts, $content = null) {
	extract( shortcode_atts( array(
			'message' => ''
		), $atts )
	);
 
	if(is_user_logged_in()) {
		return $content;
	} else {
		return '<div class="alert_red" style="color: red;">' . $message . '</div>';
	}
 
}
add_shortcode('logged_in', 'pippin_logged_in_user_shortcode');

With this function active, you will now be able to do this:

1
[logged_in message="You must be logged in to view this content"]This is text that can only be viewed when logged in[/logged_in]
Tweet Follow @pippinsplugins
is_user_Logged_in()

3 comments on “Show Message to Logged In User with a Short Code”

  1. John Shipka says:
    March 30, 2012 at 12:59 pm

    this is a great post and very helpful!

    I am working with another plugin for my forum called bbpress. I can get your plugin to work great for my pages but not for any forums. Any suggestions? Any and all help is appreciated. Thanks!

    here is the link i’m working on.
    http://appraiserpanel.com/forum/

    Reply
    • Pippin says:
      March 30, 2012 at 4:53 pm

      What happens in the forums? Does the short code come out as plain text?

    • John Shipka says:
      March 31, 2012 at 7:03 am

      Not plain text. The page content was visible. I went in another direction on the site but plan to use your plug in in the future. Very nice. Thanks!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

Sorry, no related items found.

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes
  • Plugin Development 101 – Registering a Custom Post Type
  • Plugin Development 101 – Intro to Actions

Latest Tutorials

  • Submitting Your First Pull Request to a WordPress Plugin on Github (1)

    Github is an extremely popular tool for managing WordPress plugins, and one...

  • Plugin Development 101 – Introduction to Adding Dashboard Menus (1)

    Adding new menus, both top level and sub level, to the WordPress Dashboard is a really common task for plugins...

  • Plugin Development 101 – Intro to Loading Scripts and Styles (16)

    In this part of Plugin...

Enter your email to receive automated updates when new posts are published

Latest Tweets

  • @jasonbobich hmm, interestinf
    May 19, 2013
  • @jasonbobich I haven&#039;t recently
    May 19, 2013
  • @strickland lol I passed out for two hours, so who knows
    May 19, 2013

Topics

contextual help add_shortcode meta box Tom McFarlin add_options_page Rémi Corson wp_enqueue_script featured get_user_meta attachments shortcodes register_setting Sugar Event Calendar attachment mail chimp image plugin forms login short codes authors Related posts do_action bbpress comments recent posts post types apply_filters short code taxonomies custom post type images gallery Ajax Stripe taxonomy jquery users widgets add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2011 Pippin's Plugins