Skip to content

Email

An email input field with validation for email addresses.

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

SettingDescription
Field KeyUnique identifier. Lowercase letters and underscores only.
LabelDisplay label shown above the field.
DescriptionOptional helper text shown below the field.
PlaceholderOptional placeholder, e.g. hello@example.com
Default ValueOptional 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() inside href="mailto:..." attributes
  • Use esc_html() for the visible link text

On This Page