WordPress

Shortcode

Shortcode is a bracketed tag in WordPress content, like [gallery ids="4,5"], that expands to HTML when the page is rendered. The shortcode stays in the database as plain text.

How it is measured

A plugin or theme registers a tag with add_shortcode( 'pricing', 'render_pricing' ). When the_content runs, WordPress finds matching tags and replaces them with the callback's return value. Unknown tags are printed as literal text. Find usage with SELECT ID FROM wp_posts WHERE post_content LIKE '%[pricing%'.

WP-CLI can scan too: wp post list --s='[pricing' --post_type=any --format=ids. A tag that is rendered on the front end but missing from the Plugins list is a sign the code lives in the theme.

Worked example

A marketing site has 85 pages that use [cta_banner id="12"]. The designer replaces the theme, and every page now shows the raw text [cta_banner id="12"] in the middle of the copy, because the shortcode was defined in the old theme's functions.php.

Moving the one function into a small plugin restores all 85 banners at once. The pages themselves were never edited.

How it differs

A shortcode is a text placeholder that runs PHP, while a block from Gutenberg is structured content with its own editor controls. Shortcodes work inside a Shortcode block and in the classic editor, but they have no live preview in the block editor. A plugin provides most shortcodes, and removing it leaves the tags visible.

Common errors

Defining shortcodes in the theme. Echoing instead of returning from the callback, which prints output at the top of the page. Nesting shortcodes without do_shortcode. Using a shortcode inside a widget or excerpt where it is not parsed. Leaving unused tags in content after uninstalling a plugin.

In practice

Search your content for the square-bracket tags before you remove a plugin or change a theme. Move any shortcode registered in the theme to a plugin. For new work, consider a block with a render callback.

See also

Gutenberg, Plugin

Sources

Count this on a real site.

Watch my website