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 Rendering Twice Inside the Block Editor

- 17.11.26 - ErcanOPAK

📝 WordPress: Fix a Shortcode Rendering Twice Inside the Block Editor

A classic shortcode registered through add_shortcode() can appear to render itself twice inside the Block Editor’s live preview even though the published front end only shows it once, because a page builder panel or preview sidebar that calls do_shortcode($content) on its own copy of the post content runs independently of the core Shortcode block’s own PHP render pass for the same editor session — both execute the shortcode’s callback against the same content, and since the front end’s the_content filter chain only ever runs once per request, the duplication is visible only inside wp-admin and easy to dismiss as a rendering glitch rather than a genuine double execution.

🔎 The Problem

Post content: [booking_widget location="downtown"]

Block Editor preview pane: widget renders TWICE, stacked vertically
Live front end (same post, published): widget renders ONCE, correctly

Plugin's own editor preview panel is independently calling:
  echo do_shortcode( get_the_content() );
...while Gutenberg's core/shortcode block ALSO renders the same
shortcode through its own REST preview endpoint in the same request

✅ Fix: Make Sure Only One Code Path Renders the Shortcode Per Preview

  • Audit any custom meta box, page-builder panel, or admin preview script that calls do_shortcode() directly on the post content — that’s almost always the second, redundant render path running alongside Gutenberg’s own Shortcode block.
  • If a custom preview panel genuinely needs its own rendered copy, have it render from a dedicated AJAX endpoint instead of re-running do_shortcode() against content the Block Editor is already independently previewing in the same screen.
  • Confirm on the live front end first — if it renders once there, the bug is specifically in an admin-only preview code path, not in the shortcode’s own callback, which saves you from debugging the wrong half of the system.

🚨 Why This Is Dangerous

  • Spending hours ‘fixing’ a shortcode’s callback for a duplication bug that only exists in an unrelated admin preview panel, while the actual published page was correct the entire time — and risking breaking the front-end render while chasing a problem that only ever existed in wp-admin.

If it only duplicates in the editor, the bug isn’t in your shortcode — it’s in whatever else is also rendering it.

— WordPress Admin

Related posts:

WordPress: Essential Security Hardening for Your Site

WordPress: Essential Security Hardening for Your Site

WordPress: Speed Up a Slow Site Without Touching a Single Line of Code

WordPress: Speed Up a Slow Site Without Touching a Single Line of Code

WordPress Admin Feels Slow but Frontend Is Fast

WordPress Admin Feels Slow but Frontend Is Fast

Views: 6

Post navigation

Photoshop: Fix Export As Washing Out Colors in a Wide-Gamut Document
JavaScript: Fix a WeakMap Losing Entries After a Structured Clone

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,059)
  • Get the User Name and Domain Name from an Email Address in SQL (983)
  • How to add default value for Entity Framework migrations for DateTime and Bool (981)
  • Get the First and Last Word from a String or Sentence in SQL (861)
  • How to select distinct rows in a datatable in C# (856)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (658)
  • Add Constraint to SQL Table to ensure email contains @ (613)
  • Average of all values in a column that are not zero in SQL (571)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (549)
  • Find numbers with more than two decimal places in SQL (477)

Recent Posts

  • Visual Studio: Fix Quick Actions Hiding Behind a Stale Squiggle
  • Photoshop: Fix a Smart Filter Resetting After You Relink It
  • Ajax: Fix a Cancelled Request Still Updating Stale UI State
  • C#: Fix a Span Captured by a Lambda Throwing at Runtime
  • The AI Prompt That Converts a REST Endpoint Into a Typed SDK
  • Git: Fix a Worktree Locking a Branch Needed Somewhere Else
  • Asp.Net Core: Fix a Background Service Leaking Scoped Dependencies
  • SQL Server: Fix a Columnstore Index Fragmenting After Bulk Deletes
  • Docker: Fix a Container Losing Logs After a Restart Policy
  • Asp.Net Core: Fix Output Caching Serving a Stale Authorized Page

Most Viewed Posts

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

Recent Posts

  • Visual Studio: Fix Quick Actions Hiding Behind a Stale Squiggle
  • Photoshop: Fix a Smart Filter Resetting After You Relink It
  • Ajax: Fix a Cancelled Request Still Updating Stale UI State
  • C#: Fix a Span Captured by a Lambda Throwing at Runtime
  • The AI Prompt That Converts a REST Endpoint Into a Typed SDK

Social

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