• 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

    (@catstratcat)

    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.