USP Pro provides numerous ways of collecting a user’s email address. For example, you can include the shortcode [usp_email]
to any form. Once the form is submitted, the email address will be attached to the post as a custom field. This tutorial shows one way to use this information: displaying it on the front-end as a link to contact the author.
The easy way
This is actually pretty easy to do, just open your theme’s single.php
(or content.php
or similar) template and locate the Loop. Anywhere in the loop, add the following code:
<a href="mailto:<?php echo usp_get_meta(false, 'usp-email'); ?>">Contact the post author via email</a>
Here, we are using mailto:
as the href
value in a normal <a>
tag. This means that when a visitor clicks the link, their email client will open automatically so they can send an email.
Note that this technique demonstrates one way to display submitted custom-field data using USP Pro. The key is the USP template tag, usp_get_meta()
, which you can learn more about in the Guide to USP Template Tags.
Shortcode method
Also check out [usp_meta], which is the shortcode version of usp_get_meta()
that enables you to display custom field data in Posts and Pages (via the Edit Post screen). For example, you can do this to display the submitted email on a specific Post or Page:
[usp_meta id="123" meta="usp-email"]
mailto:
attribute at Web Developers Notes »