Text Field
The Text field is a single-line input for short text content — titles, names, labels, taglines, or any short string value.
Field Settings
| Setting | Description |
|---|---|
| Field Key | Unique identifier used to retrieve the value. Lowercase letters and underscores only. |
| Label | Display label shown above the field in the WordPress editor. |
| Description | Optional helper text shown below the field. |
| Placeholder | Optional placeholder text shown inside the empty input. |
| Default Value | Optional value pre-filled when no value has been saved. |
Return Value
Returns a string. Returns an empty string "" if no value has been saved and no default is set.
Usage
php
// Get the value
$value = onemeta_get_meta( get_the_ID(), 'field_key' );
// Display with escaping
if ( ! empty( $value ) ) {
echo '<h2>' . esc_html( $value ) . '</h2>';
}
// With a default fallback
$value = onemeta_get_meta( get_the_ID(), 'field_key', 'Default text' );
Template Example
php
<?php $subtitle = onemeta_get_meta( get_the_ID(), 'subtitle' ); ?>
<?php if ( ! empty( $subtitle ) ) : ?>
<p class="entry-subtitle"><?php echo esc_html( $subtitle ); ?></p>
<?php endif; ?>
Notes
- Always escape output using
esc_html()when displaying in HTML context - Use
esc_attr()when outputting inside an HTML attribute - The
onemeta_prefix is added automatically — do not include it in your field key