Title: Help me write this shortcode
Last modified: August 20, 2016

---

# Help me write this shortcode

 *  [catstratcat](https://wordpress.org/support/users/catstratcat/)
 * (@catstratcat)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/help-me-write-this-shortcode/)
 * Hi all,
 * I want to write a shortcode to achieve the following:
 * **For each user** create a shortcode [email_”firstname”] where “firstname” is
   the user’s first name as defined in the backend.
 * This shortcode would display the following html:
 * `<a href="mailto:"user's email address">"user's email address"</a>`
 * Where “user’s email address” is the user’s email address as defined in the backend.
 * I am part the way there where I get the user info by user id, but I want this
   to be ‘dynamic’, this is to say I want this shortcode to work for each user without
   it being predefined in functions.php.
 * This is what I have so far, hope it makes sense.
 * My shortcode: [email_test]
 *     ```
       <? php
   
       add_shortcode('email_test', 'short_email_test');
   
       function short_email_test {
       $user_info = get_userdata(1);
       $user_email = $user_info->user_email;
          echo "<a href=mailto:$user_email>$user_email</a>";
       }
       ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [catstratcat](https://wordpress.org/support/users/catstratcat/)
 * (@catstratcat)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/help-me-write-this-shortcode/#post-2444581)
 * **Please note:** I suggested “firstname” in the original post but I realise this
   could be problematic as two users can have the same first name – I’d like to 
   use ‘username’ instead.

Viewing 1 replies (of 1 total)

The topic ‘Help me write this shortcode’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [catstratcat](https://wordpress.org/support/users/catstratcat/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/help-me-write-this-shortcode/#post-2444581)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
