In a theme I’m developing I would like to have a button with a mailto: href so that it when a user clicks on it, it generates the email address dependent on the post author.
I’ve managed to get it so that the email subject is generated from the post title by simply using the the_title();
I can’t seem to work out how to dynamically generate the email address though. I need to replace the “someone@example.com” part that is hard-coded below to automatically be the post author’s email that is registered in their user profile in the back end.
I was looking at get_the_author_meta(); function, but this only seems to allow you to add a parameter for ‘user_email’ and then you have to manually add the user ID, which again is no use.
<a href="https://wordpress.stackexchange.com/questions/290522/mailto:someone@example.com?subject=<?php the_title(); ?>">Apply</a>
Any help would be amazing.
2 Answers
You can use get_the_author_meta
function. You can learn more about it here: https://developer.wordpress.org/reference/functions/get_the_author_meta/
Usage in your case:
<a href="https://wordpress.stackexchange.com/questions/290522/mailto:<?php echo get_the_author_meta("user_email');?>?subject=<?php the_title(); ?>">Apply</a>