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
| 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. https://example.com |
| Default Value | Optional 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