Skip to content

Shortcode Field

A display-only field that renders the output of a WordPress shortcode inside the options panel.

A text input for saving a WordPress shortcode string as a theme option.

Overview

The Shortcode field renders a single-line text input with a Paste from clipboard button. The user types or pastes a shortcode string — the string itself is saved as the option value. Your theme then retrieves the saved string and executes it with do_shortcode() at render time.

Use it when you want users to embed a shortcode from another plugin — a contact form, a newsletter signup, a custom widget, a cookie notice, or any other shortcode-powered content — into a theme-controlled location.

For displaying static instructional text, use the Info field. For embedding arbitrary HTML directly, use the Raw field.

Field Registration

[
    'id'          => 'footer_shortcode',
    'type'        => 'shortcode',
    'title'       => __( 'Footer Shortcode', 'your-textdomain' ),
    'subtitle'    => __( 'Paste a shortcode to display in the footer widget area', 'your-textdomain' ),
    'default'     => '',
    'placeholder' => '[contact-form-7 id="123"]',
]

Field Options

OptionTypeRequiredDescription
idstringUnique field identifier — used as the option key
typestringMust be shortcode
titlestringLabel shown above the field
subtitlestringDescriptive text shown below the label
descstringAlternative to subtitle — shown in the same position
defaultstringDefault shortcode string. Default: ''
placeholderstringPlaceholder shown inside the input when empty. Default: '[my-shortcode]'
requiredarrayConditional logic rules — see Conditional Logic

Return Value

Type: string

Returns the shortcode string exactly as the user entered it — e.g. '

Error: Contact form not found.

'. Returns the default value if nothing has been saved yet. Returns an empty string '' if no default is set and nothing has been saved.

$shortcode = themeplus_get_option( 'footer_shortcode', '' );
// Returns: '[contact-form-7 id="123"]'

Usage Examples

Executing the saved shortcode

$shortcode = themeplus_get_option( 'footer_shortcode', '' );

if ( $shortcode ) {
    echo do_shortcode( wp_kses_post( $shortcode ) );
}

Contact form in the footer

[
    'id'          => 'footer_contact_form',
    'type'        => 'shortcode',
    'title'       => __( 'Footer Contact Form', 'your-textdomain' ),
    'subtitle'    => __( 'Paste a contact form shortcode — e.g. from Contact Form 7 or WPForms', 'your-textdomain' ),
    'placeholder' => '[contact-form-7 id="123" title="Footer Form"]',
    'default'     => '',
]
$form_shortcode = themeplus_get_option( 'footer_contact_form', '' );

if ( $form_shortcode ) {
    echo '<div class="footer-form">';
    echo do_shortcode( wp_kses_post( $form_shortcode ) );
    echo '</div>';
}

Newsletter signup in a banner

[
    'id'          => 'banner_newsletter',
    'type'        => 'shortcode',
    'title'       => __( 'Newsletter Signup', 'your-textdomain' ),
    'placeholder' => '[mc4wp_form id="456"]',
    'default'     => '',
]
$newsletter = themeplus_get_option( 'banner_newsletter', '' );

if ( $newsletter ) {
    echo '<div class="newsletter-banner">';
    echo do_shortcode( wp_kses_post( $newsletter ) );
    echo '</div>';
}

With a conditional field

[
    'id'      => 'enable_footer_form',
    'type'    => 'toggle',
    'title'   => __( 'Show Contact Form in Footer', 'your-textdomain' ),
    'default' => false,
],
[
    'id'          => 'footer_form_shortcode',
    'type'        => 'shortcode',
    'title'       => __( 'Contact Form Shortcode', 'your-textdomain' ),
    'placeholder' => '[contact-form-7 id="123"]',
    'default'     => '',
    'required'    => ['enable_footer_form', '==', true],
],
$enabled   = themeplus_get_option( 'enable_footer_form', false );
$shortcode = themeplus_get_option( 'footer_form_shortcode', '' );

if ( $enabled && $shortcode ) {
    echo '<div class="footer-contact">';
    echo do_shortcode( wp_kses_post( $shortcode ) );
    echo '</div>';
}

Notes

  • The field stores the shortcode string — not the rendered output. Always call do_shortcode() when using the value in your template.
  • The Paste button reads from the system clipboard — useful when copying shortcodes from another admin screen. The button shows a brief “Pasted!” confirmation.
  • Always wrap the value in wp_kses_post() before passing to do_shortcode() to strip any unexpected markup while preserving valid shortcode syntax.
  • The saved value is sanitized with sanitize_text_field()before storage — shortcode tags and attributes are preserved since they contain no disallowed characters.
  • For embedding arbitrary HTML that should not be executed as a shortcode, use the Raw field instead.

On This Page