Skip to content

Text

A single-line text input for short content like titles, names, and labels.

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

SettingDescription
Field KeyUnique identifier used to retrieve the value. Lowercase letters and underscores only.
LabelDisplay label shown above the field in the WordPress editor.
DescriptionOptional helper text shown below the field.
PlaceholderOptional placeholder text shown inside the empty input.
Default ValueOptional 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

Was this article helpful?

On This Page