Email Field
The Email field is a text input with built-in email validation. Use it for contact email addresses, support emails, or any field requiring a valid email format.
Field Settings
| Setting | Description |
|---|---|
| Field Key | Unique identifier. Lowercase letters and underscores only. |
| Label | Display label shown above the field. |
| Description | Optional helper text shown below the field. |
| Placeholder | Optional placeholder, e.g. hello@example.com |
| Default Value | Optional default email address. |
Return Value
Returns a string containing the email address. Returns an empty string if no value is saved.
Usage
php
// Get the value
$email = onemeta_get_meta( get_the_ID(), 'field_key' );
// Display as a mailto link
if ( ! empty( $email ) ) {
echo '<a href="mailto:' . esc_attr( $email ) . '">' . esc_html( $email ) . '</a>';
}
Template Example
php
<?php $contact_email = onemeta_get_meta( get_the_ID(), 'contact_email' ); ?>
<?php if ( ! empty( $contact_email ) ) : ?>
<p class="contact-email">
<a href="mailto:<?php echo esc_attr( $contact_email ); ?>">
<?php echo esc_html( $contact_email ); ?>
</a>
</p>
<?php endif; ?>
Notes
- Use
esc_attr()insidehref="mailto:..."attributes - Use
esc_html()for the visible link text