The Text field type provides a single-line text input for short text content. It's ideal for titles, names, short labels, or any content that fits on a single line without rich text formatting.
array(
'type' => 'text',
'id' => 'example_text',
'label' => 'Title',
'counter' => true,
)For Default Field Properties, see Field Types Definition.
When set to true, displays a character counter below the input showing the current character count.
The field stores the text content as a string in the database. Values are sanitized using WordPress's sanitize_text_field() function, which removes HTML tags and line breaks.
array(
'type' => 'text',
'id' => 'product_title',
'label' => 'Product Title',
'description' => 'Enter the product title.',
'required' => true,
)array(
'type' => 'text',
'id' => 'meta_title',
'label' => 'Meta Title',
'description' => 'SEO title for search engines (recommended: 50-60 characters).',
'counter' => true,
'attributes' => array(
'maxlength' => 60,
),
)array(
'type' => 'text',
'id' => 'company_name',
'label' => 'Company Name',
'description' => 'Your company or organization name.',
'attributes' => array(
'placeholder' => 'Enter company name...',
'maxlength' => 100,
'class' => 'company-name-input',
),
)// Get the text content from the meta field
$product_title = get_post_meta( get_the_ID(), 'product_title', true );
if ( ! empty( $product_title ) ) {
echo '<h1 class="product-title">' . esc_html( $product_title ) . '</h1>';
}
// Using in an attribute
$company_name = get_post_meta( get_the_ID(), 'company_name', true );
if ( ! empty( $company_name ) ) {
echo '<input type="hidden" name="company" value="' . esc_attr( $company_name ) . '">';
}array(
'type' => 'toggle',
'id' => 'enable_custom_title',
'label' => 'Use Custom Title',
),
array(
'type' => 'text',
'id' => 'custom_title',
'label' => 'Custom Title',
'description' => 'Enter a custom title to override the default.',
'attributes' => array(
'placeholder' => 'Enter custom title...',
),
'conditions' => array(
array( 'field' => 'enable_custom_title', 'value' => true ),
),
)$f = new \Wpify\CustomFields\FieldFactory();
$f->text(
label: 'Title',
required: true,
counter: true,
);- The text field is designed for single-line content; for multi-line content, use the
textareafield type instead - Values are sanitized with
sanitize_text_field(), which strips HTML tags and converts line breaks to spaces - For security, always use
esc_html()when outputting text content andesc_attr()when using in HTML attributes - The
counterproperty is useful for SEO fields or any input where character count matters - Use the
maxlengthattribute to enforce a character limit at the browser level - The field validates that a value is provided when the
requiredproperty is set totrue