A Cozmoslabs Product
Documentation / Developer Knowledge Base / Shortcodes / Current User link shortcode

Current User link shortcode

This function adds a shortcode that display a link if user is logged in.

Make sure to:

  • change link and text on line 11
Shortcode:

[current_user_link]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * Current User link shortcode
 * Use like so: [current_user_link] This is displayed only if current user is logged in.
 */
 
add_shortcode( 'current_user_link', 'wppbc_current_user_link' );
function wppbc_current_user_link( $atts, $content ) {
   if ( is_user_logged_in() ) {
      $id = get_current_user_id();
      // make sure to change the URL to represent your setup.
      return "<a href='http://website.com/user-listing-page/user/{$id}'>Your User Page</a>";
   }
 
   return ;
}

Profile Builder Pro

Create beautiful front-end registration and profile forms with custom fields. Setup member directories, custom redirects, cutomize user emails & more using the all in one user management plugin.

Get Profile Builder

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket