Name and Last Name Variables in HTML Template

Hi!

I'm using HTML Email Templates, and I would like to use the user's name and last name on the e-mail template. One of the templates has a username variable, so I suppose it's also possible to fetch the first and last name.

Thanks in advance!

  • Adam Czajczyk

    Hello Pedro,

    I hope you're well today and thank you for your question!

    Currently available placeholders (variables) that you may use in your custom Email Templates are:

    {MESSAGE}
    {SIDEBAR_TITLE}
    {FROM_NAME}
    {FROM_EMAIL}
    {BLOG_URL}
    {BLOG_NAME}
    {ADMIN_EMAIL}
    {BLOG_DESCRIPTION}
    {DATE}
    {TIME}

    For more explanation on this variables please go to your site's dashboard "Settings -> HTML Email Template" page and click on "List of variables that can be used in template" link.

    I suppose it may be possible to add some more variables with a bit of custom code but I'm not sure (yet) how complex this may be. The "user name" and "last name" - would you like to fetch them from user profile (if a sender's email is associated wit a user account) or from some other source? Could you shed some light on this for me please?

    Best regards,
    Adam

  • Adam Czajczyk

    Hello Pedro,

    Thanks for your replay!

    The {USER_NAME} variable is replaced with WP user "display name" so this may be a nickname/login, first name, last name, both names or anything that user chose in his/her profile as a value of "Display name publicly as" option. I admit I'm not sure why this variable is not on a list. I reviewed the plugin code and it seems that there's no more undocumented variables available though.

    Furthermore, there's no direct hooks in a plugin that could be used to add more variables/placeholders and the only reasonable way I can see would be to hook to core wp "wp_mail()" filter. This would however require custom function to be called after the "wp_mail()" has been modified by plugin and before it was executed. I'd say this would be a bit outside the scope of this forum and would require custom coding for which you may want to ask on our "Jobs & Pros" job board here (please note: no WPMU DEV staff involved!):

    https://premium.wpmudev.org/wordpress-development/

    There's a simpler way but it would require changing plugin's code directly which is not recommended and also all these changes would be lost upon first update. If you wish to go this way anyway (please note: this would be at your own risk!) let me know please and hopefully I'll be able to provide you with a code for this.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.