November 2013 - ACROWEB

Build a Simple User Logged In Shortcode in WordPress

Posted by | Basic Coding, WordPress | 3 Comments

If you are looking for the best place to host buy cheap xanax your WordPress site, knowing that it will run very fast and always be secure, be sure to check out WPEngine

A Simple User Logged in Shortcode in WordPress

Open up your functions.php file in your theme and add the following code:

function check_user ($params, $content = null){
  //check tha the user is logged in
  if ( is_user_logged_in() ){

    //user is logged in so show the content
    return $content;



    //user is not logged in so hide the content



//add a shortcode which calls the above function
add_shortcode('loggedin', 'check_user' );

And there you have it, you can then write something like:

[loggedin]This content will only be displayed to logged in users.[/loggedin]

…and it should work.

Share This

Have a project that you want to talk about? Get A Quote