Skip to content

Shortcode Field

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

Overview

The Shortcode field executes a WordPress shortcode and renders its output directly inside the options panel — no input, no saved value. Use it to embed dynamic content inside the panel such as a custom color palette preview, a live font specimen, a system status table, a license key validator, or any other output generated by a registered shortcode.


Field Registration

php

[
    'id'        => 'color_palette_preview',
    'type'      => 'shortcode',
    'title'     => __('Color Palette Preview', 'your-textdomain'),
    'shortcode' => '[mytheme_color_preview]',
]

Field Options

OptionTypeRequiredDescription
idstringUnique field identifier — not stored, but required for internal rendering
typestringMust be shortcode
titlestringLabel shown above the shortcode output
descstringHelp text shown below the output
shortcodestringThe shortcode string to execute — e.g. [my_shortcode attr="value"]
requiredarrayConditional logic rules — see Conditional Logic

Return Value

None. The Shortcode field stores no value and returns nothing from themeplus_get_option().


Usage Examples

System status table

Register a shortcode that outputs theme or server environment info:

php

add_shortcode( 'mytheme_system_status', function() {
    $php_version = phpversion();
    $wp_version  = get_bloginfo( 'version' );
    $theme       = wp_get_theme();

    ob_start();
    ?>
    <table class="widefat">
        <tbody>
            <tr>
                <td><?php esc_html_e( 'PHP Version', 'your-textdomain' ); ?></td>
                <td><?php echo esc_html( $php_version ); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e( 'WordPress Version', 'your-textdomain' ); ?></td>
                <td><?php echo esc_html( $wp_version ); ?></td>
            </tr>
            <tr>
                <td><?php esc_html_e( 'Theme Version', 'your-textdomain' ); ?></td>
                <td><?php echo esc_html( $theme->get( 'Version' ) ); ?></td>
            </tr>
        </tbody>
    </table>
    <?php
    return ob_get_clean();
});

Then register it as a Shortcode field:

php

[
    'id'        => 'system_status',
    'type'      => 'shortcode',
    'title'     => __('System Status', 'your-textdomain'),
    'shortcode' => '[mytheme_system_status]',
]

Font specimen preview

php

add_shortcode( 'mytheme_font_preview', function() {
    $font = themeplus_get_option( 'body_typography', [] );
    $family = $font['font-family'] ?? 'inherit';

    return '<p style="font-family: \'' . esc_attr( $family ) . '\', sans-serif; font-size: 18px; line-height: 1.6;">
        The quick brown fox jumps over the lazy dog.
    </p>';
});

php

[
    'id'        => 'font_preview',
    'type'      => 'shortcode',
    'title'     => __('Font Preview', 'your-textdomain'),
    'shortcode' => '[mytheme_font_preview]',
]

License key status

php

add_shortcode( 'mytheme_license_status', function() {
    $status = get_option( 'mytheme_license_status', 'inactive' );

    $label = $status === 'active'
        ? '<span style="color: #00a32a;">&#10003; ' . esc_html__( 'Active', 'your-textdomain' ) . '</span>'
        : '<span style="color: #d63638;">&#10007; ' . esc_html__( 'Inactive', 'your-textdomain' ) . '</span>';

    return '<p>' . $label . '</p>';
});

php

[
    'id'        => 'license_status_display',
    'type'      => 'shortcode',
    'title'     => __('License Status', 'your-textdomain'),
    'shortcode' => '[mytheme_license_status]',
]

With a conditional

php

[
    'id'      => 'show_system_info',
    'type'    => 'toggle',
    'title'   => __('Show System Info', 'your-textdomain'),
    'default' => false,
],
[
    'id'       => 'system_status',
    'type'     => 'shortcode',
    'title'    => __('System Status', 'your-textdomain'),
    'shortcode' => '[mytheme_system_status]',
    'required' => ['show_system_info', '==', true],
],

Notes

  • The id must still be unique within the section even though the field stores no value.
  • The shortcode is executed server-side at render time — the output is static HTML embedded in the panel. It does not re-execute on save or on live preview changes.
  • Always use ob_start() / ob_get_clean() inside shortcode callbacks that use echo or template tags, and return the buffered output rather than echoing directly.
  • Keep shortcode output lightweight — avoid heavy database queries or external HTTP requests inside shortcodes registered for panel display.
  • For instructional text without dynamic output, use the Info field instead.

On This Page