Paragraph tags in content field with Divi; Editor lint error with Shortcode tag

Hi,

after the latest update I’m facing some issues with the plugin.

  1. The “Field content” is stripping any <p> in the text.
  2. The syntax <Shortcode my_shortcode /> is causing an error message in the template editor - Unclosed “div” Tag

Hello, thank you for issue description.

  1. I tried <Field content /> with a post type using Gutenberg, and another post type with classic editor. Both are working correctly on my end - the content is formatted with paragraphs. Could you provide any other detail that might help me catch the issue in action?

  2. I’m not seeing any error message in the editor, using the same code snippet posted in the WP support forum: <Shortcode my-shortcode />. It could be that there is actually an unclosed div tag somewhere else in the template.


By the way, in the Discourse editor, inline code can be wrapped in backticks like `this` to prevent it from getting removed in the post. For larger code blocks, they can be wrapped in ```html (before) and ``` (after the block) on their own lines.

Hi Eliot,

thanks for the reply.

For the <p> issue
I’m using Divi with classical editor. In this case Divi is not used to build the content - its simply from the classical editor. Header tags (h1,h2, …) are not touched.

For the error message issue → see the two images. A simple

<Note><Shortcode my_shortcode /></Note>

produces the error - there are no other tags.

Image3

Image2

Just checked - the <Shortcode /> issue is only, when the tag is wrapped into a <div> or any other tag.

I see, it looks like the editor’s “linter”, which checks for valid syntax, needs to know that the Shortcode tag can be self-closing. Probably it will not show the warning if it’s like this:

<Shortcode my_shortcode></Shortcode>

For the paragraph tags in content field, it seems to be a compatibility issue with Divi. Will see if I can track down the cause.

Concerning the shortcode → you are right - it works plain.

For the editor issue - I just want to make clear - I’m NOT using the DIVI builder for the relevant content - just the classic editor in visual mode.

And it worked in 2.4.4 - so some change between the version most likely cause the issue.

Hm, I’m not seeing any issue with the classic editor in visual mode.

Does Divi (or another plugin you might have installed) have a setting that controls post content formatting?

Not that I’m aware of - and I can roll back to 2.4.4 and all is fine again.

Could you try deactivating Divi to see if the issue still happens? I don’t have a copy of Divi at hand, and it seems to be the only difference compared to my test site, where paragraph tags in post content are working.

OK, it seems to be an DIVI issue.

Tried the suggested and the issue was gone. Same result as with 2.4.4 :slight_smile:

1 Like

Ah, good to know that it’s specific to Divi - thanks for confirming.

I found a fairly new version of Divi Builder on GitHub, so I’ll use that to figure out how we can improve compatibility. The issue seems to be related to the_content filter, which filters the post content with a series of formatting functions, including wpautop that adds paragraph tags. Somehow, when Divi is active, that’s not getting applied.

Hi, I saw the new release 3.0.1 and just wanted to ask if the issue with content filed in DIVI has been addressed as well. Did not find a mention in the release notes.

Hey Ralf, we haven’t been able to address the issue with Divi yet, but you’ll find that the issue when using the <Shortcode /> tag has been resolved in the 3.0.1 update. We’ll follow up here when we’re able to address the issue with Divi.

This Shortcode helped me out and works properly with 3.0.1 & DIVI

// [post type="content" id="2"]
// [post type="title" id="2"]

function post__shortcode( $atts ) {
    $a = shortcode_atts(
        array (
            'id'   => false,
            'type' => "content",
        ), $atts );

    $id   = $a [ 'id' ];
    $type = $a [ 'type' ];

    // bad id
    if ( ! is_numeric( $id ) ) {
        return '';
    }

    // find the post
    $post = get_post( $id );

    // bad post
    if ( ! $post ) {
        return '';
    }

    // allow for other post attributes
    switch ( $type ) {

        case "content":
            return $id === get_the_ID() || $id === get_queried_object_id()
                ? '' // no recursive loops!
                : apply_filters( 'the_content', $post->post_content );

        case "title":
            return $post->post_title;
    }

    // nothing to see here
    return '';
}

add_shortcode( 'post', 'post__shortcode' );

Hi,
any change this get paragraph issue in DIVI fixed in the near future - if not I have to change my code on all my pages to be able to update.

I’ve pinged @eliot again on this, I’ll try to get an ETA from him.

1 Like

It seems that the Divi issue is fixed. Was it fixed by intention or accident? :slight_smile: