Layouts and Post Excerpts [BUG?]

Hello there, I’m in the process of designing my first single post layout, and I think I may have found a bug.

I’ve been using the Block Editor “More Block” to separate my excerpt from the rest of my post content, but it seems that the dynamic content tag {{dc:post:excerpt}} isn’t respecting it; it is printing both my excerpt and more (as I would expect without a “More” tag).

For troubleshooting’s sake, I’m trying to call my excerpt in an unassigned Post Layout using the Layout Builder. I checked to see if the excerpts were working right in other places in a looper I created just to make sure, and they indeed are working properly elsewhere, so I’m guessing there may be an oversight in the Layout Builder code that is not respecting the excerpt’s More tag.

For clarity, here is what my post looks like in the block editor.

And here is what my post layout looks like (plus my notation). Notice that the “read more” block is not respected in my post layout and it shows more text in the excerpt than it should.

Hello @bobbybosler,

Thanks for writing to us.

The dynamic content {{dc:post:excerpt}} renders the data from the Excerpt box
Edit-Post-‹-Barber-Site-—-WordPress

In case if you are editing post content with the page builder you check the excerpt content. I would
hello-test-Content-Pro

I would suggest you add the post excerpt content in the Excerpt box or Manual Excerpt to render separate excerpt by the using {{dc:post:excerpt}}.

On the post details page or post single page the all the content or shortcode will be outputted as content on the single page.

Thanks

@prakash_s,

I understand how the Manual Excerpt box works, but I also understand how Wordpress works, too. In normal Wordpress practice, the_excerpt is supposed to return, in descending priority, the following:

  1. Whatever is in the contents of the “manual excerpt” box (if populated),
  2. All text in the post content before the <!--more--> tag or the “More” block (if present)
  3. Or the first 55 words of the post content (if there is nothing in the excerpt box and there is no more tag or block).

That being said, it appears that priority 2 is not working in the conditions I reported above, which is a bug. When my manual excerpt box is empty and a more tag is in place, I do NOT get everything before the more tag (2), but I get the first 55 words of my post content (3).

I accept your suggestion as a temporary workaround, but I would like for you to have the development team look into the issue I reported to see if they can get it to work according to expected practices in Wordpress.

Hello @bobbybosler,

The dynamic content {{dc:post:excerpt}} renders the data from the Excerpt box and Manual Excerpt If the content is not found on these boxes then it will render the data from the the_content on the basis of the excerpt length specified in the Theme Options–>Blog–>Excerpt length Please remember that it removes any tag or shortcode from the content while rendering the excerpt content.

Thanks

@prakash_s,

Ooook, then I’m requesting that the dynamic content {{dc:post:excerpt}} render the option number 2 in my list above like every other excerpt rendered in the Wordpress universe. Please pass the request along to the dev team.

Actually, @prakash_s, you are wrong about what {{dc:post:excerpt}} renders. Please see this sandbox page and the looper present there. Here is a screenshot:


The first and fourth posts do not have any more tags in the post and it renders the first 55 words. However, the second and third do have a more tag in the post and it only renders the text before the more tag. This is using the {{dc:post:excerpt}}, so it does work as I expect it to, but just not on a post single page layout!

Here is an image to show how my posts are set up. Note that I have no manual excerpts used in any of these posts other than the “more” tag.

If you can’t help me, please escalate this to someone who understands my question.

Hi @bobbybosler,

I have tried and able to replicate the issue at our end, I will report this issue to our issue tracker so this issue will be queued for investigation and fixing by our development team.
Please stay tuned for succeeding releases with the fixes.

Thanks

@tristup,

Thank you!!

Hi @bobbybosler,

You’re welcome. If you have any other concerns regarding our theme features, feel free to reach us.

Thank you.

Hi @bobbybosler,

I’ve taken a look at this, and it makes sense what you’re describing if I compare it to what I’m reading to here: https://codex.wordpress.org/Customizing_the_Read_More

However, I’ve tested this in the Twenty Twenty and Twenty Twenty-One themes and I’m getting the same result as Pro. I’ve also tried using the block editor and classic More tag. The only change I made to those themes was swapping the_content for the_excerpt as described. It didn’t seem to care where the “more tag” was placed. Perhaps this is a regression in WordPress code, or their documentation isn’t accurate. The

Under the hood, using {{dc:post:excerpt}} is the equivalent of calling the_excerpt but we strip out the ellipsis and allow the 55 character limit to be adjusted by passing a length parameter.

I’ve checked the WordPress source code as well, and from what I can tell it does this:

  1. Directly return a manual excerpt if one is found
  2. Get the content until it reaches the end or encounters the more tag. Return this value limited to 55 characters.

I’ve also poked around the WordPress core code a bit and ran into this in wp-includes/post-template.php in the get_the_content function:

if ( $elements['more'] ) {
  $output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
} else {

I don’t understand why they are appending $content[1] at the end. If I comment that out, it seems to work just like you’ve described here.

Regretfully, I don’t see anything I can do on our end to correct this problem at this point.

@alexander,

Thank you for looking into this. I opened a ticket with Wordpres Core and hopefully they will take a look. By the way, I have no idea if I described the issue accurately by saying that the_excerpt() observes the <!--more--> tag everywhere except for on the single-post page. I included a link in the report to this thread.

Hi @bobbybosler,

I have checked your ticket at WordPress.org and I would request you to check the reply given.

Thanks

@tristup,

Yes, I saw the reply. Helpful. And I’ve since found an alternative solution to achieve my desired outcomes, which I will post below…

class MyClass
{
    /**
     * Echo the content before the <!--more--> tag
     */
    public static function getContentBeforeMore()
    {
        global $more;
        $more = false;
        the_content(false);
        $more = true;
    }

    /**
     * Echo the content after  the <!--more--> tag
     */
    public static function getContentAfterMore($removeMoreTag = true)
    {
        $content = get_the_content(null, true);
        $content = apply_filters( 'the_content', $content );
        $content = str_replace( ']]>', ']]&gt;', $content );
        // Remove the empty paragraph with the <span id="more-.."></span>-tag:
        if($removeMoreTag)
        {
            $content = preg_replace('/<p><span id="more-\d+"><\/span><\/p>/m', '', $content);
        }
        echo $content;
    }
}

function printContentBeforeMore() {
    MyClass::getContentBeforeMore(); 
}
add_shortcode('content_before_more', 'printContentBeforeMore');

function printContentAfterMore() {
    MyClass::getContentAfterMore(); 
}
add_shortcode('content_after_more', 'printContentAfterMore'); 

I put this in my functions.php and used the shortcode [content_before_more] to return the content before the more tag and the shortcode [content_after_more] to return the remainder of the post.

The only hiccup I’ve found is that these shortcodes do not return the content as a child of the page builder element where they are placed, but instead they show up as a sibling to it, which makes styling a little more complicated. Not sure why it’s doing that.

Hope this helps someone!

Hi @bobbybosler,

Nice job getting that worked out! I also appreciate you taking the time to get it checked out by WordPress core. I’ve never needed that functionality specifically, but could have easily drawn the same conclusions reading their docs. Bummer that they don’t have an answer/alternative, but really nice to see you got something working. Thanks for sharing it with everyone!

As for it working with builder content, unfortunately there isn’t really a way to get that working. The builder renders out a tree of elements (parent/child relationships) and there isn’t an effective way to track the start/stop points. I understand your workflow here is to have very specific portions of the content split out - so the manual excerpt and/or adjusting the excerpt length aren’t viable options. This might be a good use case for ACF fields since you could build a structure for your data in the backend and pull it through into the design.