Text, Text area, Email and URL
4 min read
These four types store a piece of text in a normal database column. They differ in how the text is cleaned before saving and in the control the editor sees.
Type | Type id | Column (default) | Allowed SQL types | Control |
|---|---|---|---|---|
Text |
|
|
| One-line input |
Text area |
|
|
| Multi-line box (4 rows, 5 in the modern style) |
|
|
| Browser email input | |
URL |
|
|
| Browser URL input |
None of these types has its own Type settings. They use the options described in Settings every field has: default value, placeholder, instructions, required, min and max length, and the display options.
To use another column size, open the field's SQL column options (see Field groups) and choose a type from the allowed list. For example set Text to VARCHAR(100) or TEXT.
Column functions. A field can also compute its value in the database layer. Allowed functions: Text current_timestamp, md5, uuid, sha1, upper, lower; Text area upper, lower, sha1; Email and URL uuid. A field with a function cannot have a default value. upper and lower are applied when the value is saved; uuid fills in a generated UUID only when the value is empty.
Text
Stores a single line.
Cleaning on save: HTML tags are removed, surrounding spaces are trimmed, line breaks are turned into spaces, and invalid characters are dropped. If the field has a Max length, the text is cut to that many characters.
Returns: a string.
Prints: the text, HTML-escaped.
Template usage
$title = wpmcf_get_field( 'product', 'tagline' ); // "Fast & light" (raw, not escaped)
echo esc_html( $title ); // escape it yourself
wpmcf_the_field( 'product', 'tagline' ); // <span class="wpmcf-field-value">Fast & light</span>
wpmcf_the_field( 'product', 'tagline', null, [ 'wrap' => false ] ); // Fast & light[wpmcf_field group="product" field="tagline"]
[wpmcf_field group="product" field="tagline" id="42" wrap="false" default="No tagline"]wpmcf_get_field() returns the stored string unescaped. Escape it for the place you print it (esc_html(), esc_attr(), esc_url()).
Text area
Stores several lines.
Cleaning on save: HTML tags are removed and invalid characters dropped, but line breaks are kept. Trailing blank lines are trimmed.
Returns: a string with \n line breaks.
Prints: HTML-escaped. Line breaks are not converted to <br>; a browser shows them as one paragraph. To keep the breaks, use nl2br() or wpautop():
echo wpautop( esc_html( wpmcf_get_field( 'product', 'summary' ) ) );Use a WYSIWYG editor when editors need formatting or links.
Cleaning on save: the value goes through WordPress sanitize_email(). A value that is not a valid address is saved as empty (NULL). Letter case is kept.
Returns: the address as a string (or null when empty).
Prints: the address as plain escaped text. It is not turned into a mailto: link. Build the link yourself:
$mail = wpmcf_get_field( 'contact', 'email' );
if ( is_email( $mail ) ) {
printf( '<a href="mailto:%1$s">%1$s</a>', esc_attr( $mail ) );
}URL
Cleaning on save: the value goes through esc_url_raw(). A missing scheme gets http:// (example.com becomes http://example.com), spaces are encoded, and dangerous schemes such as javascript: are removed, which saves an empty value. A relative address such as /contact is kept as it is.
Returns: the URL string.
Prints: the URL, escaped for use in an attribute (esc_url()). It is not wrapped in a link. For a clickable button with link text and a new-tab option, use the Link type.
$site = wpmcf_get_field( 'company', 'website' );
if ( $site ) {
printf( '<a href="%s" rel="noopener">Visit website</a>', esc_url( $site ) );
}[wpmcf_field group="company" field="website" format="url" wrap="false"]Edit screen
Type | What the editor sees |
|---|---|
Text, Email, URL | A one-line input with the field's placeholder, |
Text area | A resizable box with the same limits. |
Changing the type later
Text can be switched to Text area, Password or URL, and Email to Text, Text area, Password or URL, without a data backup. Switching to a different kind of type (for example Text to Number) may need a conversion: the builder warns you and keeps a backup column. See Field groups.
Troubleshooting
- My line breaks disappear on the site. Text area keeps them in the data, but HTML collapses them. Use
wpautop()ornl2br(). - The email field is empty after saving. The address was not valid (for example it contained a space). The field is saved empty.
- My URL got
http://in front. The URL type completes a missing scheme. Type the full address, includinghttps://. - A short value passes my Min length. Min length is enforced by the browser only; use Max length or your own check in code. See Settings every field has.
Still stuck? Contact support