Skip to content

URL

A URL input field with validation for web addresses and external links.

URL Field

The URL field is a text input with built-in URL validation. Use it for website addresses, external links, social media profiles, or any field that requires a valid URL.


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. https://example.com
Default ValueOptional default URL.

Return Value

Returns a string containing the URL. Returns an empty string if no value is saved.


Usage

php

// Get the value
$url = onemeta_get_meta( get_the_ID(), 'field_key' );

// Display as a link
if ( ! empty( $url ) ) {
    echo '<a href="' . esc_url( $url ) . '" target="_blank" rel="noopener noreferrer">';
    echo esc_html( $url );
    echo '</a>';
}

Template Example

php

<?php $website = onemeta_get_meta( get_the_ID(), 'website_url' ); ?>

<?php if ( ! empty( $website ) ) : ?>
    <a href="<?php echo esc_url( $website ); ?>"
       target="_blank"
       rel="noopener noreferrer"
       class="btn btn-outline">
        Visit Website
    </a>
<?php endif; ?>

Notes

  • Always use esc_url() when outputting URL values in HTML — never echo raw
  • Add rel="noopener noreferrer" on external links that open in a new tab

On This Page