Search code examples
wordpresspostmailtoauthor

get author email for single post


Hello All I was wondering if someone could help me out. I have multiple users for my blog and they are allowed to create posts. I would like to create a mailto: link on the single.php post for that specific post type. I would like the mailto: email to be the author's email of that specific posts so that a viewer could email the author of the post.

I am aware that wordpress has the function:

<?php $user_email = get_the_author_meta('user_email'); ?>

this function stores the data, i would really appreciate it if someone could help me display a mailto: link with this function.


Solution

  • You can simply echo the value where you need it. For example:

    <a href="mailto:<?php echo get_the_author_meta('user_email'); ?>">Click here to email author</a>
    

    Or, more readable:

    <?php 
        $user_email = get_the_author_meta('user_email'); 
        echo '<a href="mailto:' . $user_email . '">Click here to email author</a>';
    ?>