📝 The Shortcode That Showed Up as Literal Brackets Instead of Running
A shortcode printing as its raw text – the literal brackets and name, unprocessed – almost always means do_shortcode() never ran against that specific piece of content, even though the shortcode itself is registered correctly and works fine elsewhere. The usual causes: the shortcode was registered too late (after the content filters that process shortcodes already ran for that request), or it was placed somewhere – a text widget, a field pulled in through a custom template – that was never routed through the_content or do_shortcode at all.
🔎 The Problem
// Registered on a hook that runs AFTER the_content'"'"'s shortcode
// processing has already happened for the current request:
add_action('"'"'wp_footer'"'"', function () {
add_shortcode('"'"'promo_banner'"'"', function () {
return '"'"'<div class="promo">Sale ends soon!</div>'"'"';
});
});
// Any post containing [promo_banner] renders the literal text
// "[promo_banner]" on the page - the shortcode wasn'"'"'t registered yet
// at the point WordPress processed that content'"'"'s shortcodes.
// Separately, a widget area or a custom field displayed through a
// template that calls the raw value directly:
echo get_post_meta($post_id, '"'"'custom_text'"'"', true);
// Never passed through do_shortcode() at all - any shortcode inside
// that meta field prints as plain, unprocessed text, regardless of
// whether it'"'"'s registered correctly.
✅ Fix: Register Early, and Explicitly Process Anywhere Shortcodes Are Expected
- Shortcodes need to be registered on the init hook (the standard, documented place for it) or earlier – registering one later, inside a hook that fires during or after page rendering, means it simply doesn’t exist yet at the point WordPress’s content filters go looking for registered shortcodes to process.
- Anywhere a shortcode is expected to work outside the main post content – a widget, a custom field, a template partial – the value needs to be explicitly passed through do_shortcode() before being echoed; WordPress only auto-processes shortcodes inside the_content and a small number of other specific, built-in locations, never automatically everywhere text happens to be printed.
- Text widgets specifically depend on the widget_text_content filter (or the older widget_text filter) actually having do_shortcode hooked to it – a theme or plugin that’s removed or never added that filter will show raw shortcode brackets in every text widget regardless of how correctly the shortcode itself is defined.
⚠️ Why It’s Confusing That the Shortcode ‘Works Everywhere Else’
- The exact same shortcode, in the exact same WordPress installation, correctly rendering inside a normal post’s content while showing as raw brackets inside a widget or a custom field is the single most confusing part of this bug – it creates a strong (and wrong) impression that the shortcode’s own code must be broken, when the actual issue is entirely about WHERE do_shortcode() does and doesn’t run automatically.
- A late registration timing bug specifically can be intermittent-feeling across different pages of the same site, if some requests happen to load a plugin or hook in a different order than others – which makes it look like a caching issue or a random glitch before the actual registration-timing cause is found.
A shortcode only ever runs where something explicitly calls do_shortcode – everywhere else, WordPress prints exactly the raw brackets it was given, and never assumes it should try to interpret them.

