Why My Shortcode Output Got Scrambled

In WordPress block templates, a shortcode block runs paragraph formatting over your shortcode's HTML. One block swap fixes it.

Why My Shortcode Output Got Scrambled: nested carved boxes slipped out of order on a longhouse workbench

Symptom: a shortcode that rendered perfectly inside a post came out mangled when I placed it in a theme template. Links landed inside the wrong elements. A “view all” link ended up nested inside the first card, so clicking it opened the card instead.

Cause: order of operations. When WordPress renders a block template, it expands shortcodes in the raw template first, then renders the blocks. The Shortcode block’s render step runs wpautop() over its contents, the function that turns line breaks into <p> and <br> tags. By then, its contents are your finished HTML. wpautop wraps and splits it, the browser repairs the broken nesting its own way, and you get scrambled output.

In post content the order is the other way round (paragraph formatting first, shortcodes second), which is why the same shortcode works fine there.

Fix: in templates, put shortcodes in a Custom HTML block instead. It has no render step, so the shortcode’s output passes through untouched.

<!-- before: mangled in templates -->
<!-- wp:shortcode -->

Runestones · short field notes

<!-- /wp:shortcode --> <!-- after: untouched --> <!-- wp:html -->

Runestones · short field notes

<!-- /wp:html -->

Lesson: “it works in a post” doesn’t mean it works in a template. Same code, different pipelineCI/CD pipeline An automated line that tests and deploys every change: commit the code, and the pipeline checks it and rolls it out the same way every time..

Applies to: WordPress block templates using the Shortcode block (seen on WordPress 7.1). Checked October 2026.

ᛟ ᛟ ᛟ