Shortcodes and </p> tags (2) shows errors like
No p element in scope but a p end tag seen.
on some of my pages

I’ve created a test site:

shortcode is just a placeholder dummy (with a div)
<div class="test" >test</div>

I see a nonconform </p> in the html on:

{{< dummy >}}
{{< dummy >}}

some text
{{< dummy >}}

{{< dummy >}}
more text

HTML look like e.g. this:

<p><div class="test" >test</div>

<div class="test" >test</div>

There is no issue if the shortcode is
<span class="test" >test</span>

So currently the user of a shortcode has to know if the shortcode is in a block or not.

Something like this was reported a long time ago:

and there is a pending issue:

As far as I know the closing <p> tag is optional. So I’m OK with the <p> - but not with the </p> tag.

I would like to know:
Look’s like a “block” shortcode has to be used with a preceding and following empty line in the content files.
Is there anything I can do on the shortcode side to fix my pages?

Not on the shortcode side. But you can do a simple replace func checking for those stray p closing tags in your .Content and remove them.

If you need something fancier see this.

1 Like

Hej - cool - thx for pointing me into the right direction!

I did:

{{ .Content | replaceRE "<p><div" "<div" | replaceRE "(?s:</div>\n?</p>)" "</div>" | safeHTML }}

This fixed the first two test cases. Remaining

{{< dummy >}}
more text


<div class="test" >test</div>

more text</p>

I’ll do some more tests with real content.
Thx again!


Hi, can we reopen that?

A pre-deployment cleaning process is error-prone, we need to address that behaviour in Hugo directly to turn off <p>-wrapping in MD for certain pages, e.g. landing pages.


Hi @Mario, please create new a new topic describing the details of your problem/question. See

N.B. We discourage reviving old topics because people who participated in those discussions of yesteryear are usually not here anymore and they rarely reply to questions. It is best to open a new topic rather than bumping an old one.

In addition to what @jmooring said above I would like to add that this topic is from 2018, back then Hugo used a different default Markdown processor than the one that is used currently.

Therefore this topic and the related GitHub issue are outdated.