Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Wordpress

WordPress: Fix a Shortcode That Renders as Plain Text Instead of Running

- 27.09.26 - ErcanOPAK

📝 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.

— WordPress Admin

Related posts:

WordPress: Use WP-CLI to Manage 100 Sites in 10 Minutes

WordPress: Use WP-CLI to Manage 100 Sites in 10 Minutes

WordPress: Recover a Site After an Auto-Update Breaks the Admin Dashboard

WordPress: Recover a Site After an Auto-Update Breaks the Admin Dashboard

WordPress Pages Look Different After Theme Updates

WordPress Pages Look Different After Theme Updates

Views: 7

Post navigation

Visual Studio: Fix a Code Analyzer That Stops Flagging Issues After a NuGet Update
Windows 11: Fix Focus Assist That Silently Turns Itself On During a Screen Share

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com