• Resolved cxtinac

    (@cxtinac)


    I’m importing 100’s of blog posts to a new site, and many start the content with a lead-in using <blockquote>...</blockquote> tags.

    I’m experiencing an issue which I’ve reduced to this as the simplest Post content case:

    <blockquote>This is inside the blockquote</blockquote>
    And this should be outside!

    The expected html output using a template that only outputs clean the_content() would be something like:

    <div id="post-3061">
    <h2>Test Blockquote</h2>
    <div><p><blockquote>This is inside the blockquote</blockquote><p>
    And this should be outside!
    </p></p>
    </div></div>

    i.e. displaying only the first text section wrapped in blockquote tags. But the actual output is:

    <div id="post-3061">
    <h2>Test Blockquote</h2>
    <div><blockquote>This is inside the blockquote<p>
    And this should be outside!
    </p></blockquote>
    </div>
    </div>

    i.e. the complete content gets output before the closing blockquote is output.

    It appears this can be fixed by adding this filter:

    function gwc_fix_blockquote( $content ){
    	$needle = '<blockquote>';
    	if ( substr($content, 0, strlen($needle)) === $needle ){
    		return '<p></p>' . $content;
    	}
    	return $content;
    }
    add_filter( 'the_content', 'gwc_fix_blockquote' );

    -prepending an empty <p> tag to the actual post content.

    Note that wpautop is disabled in this install.
    I have a suspicion this is related to code in wp-includes/formatting.php, but I have not dug too deeply, since I have a workaround.

    Am I missing something? Or is this intended behavior?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m unable to replicate such behavior. How did you import the content? In my testing, imported content becomes a classic block. It appears exactly as imported when wpautop is disabled. When converted to normal blocks, p tags are inserted despite wpautop being disabled. This is expected, however, the p tags are properly inserted. The HTML ends up being

    <div class="entry-content">
    <blockquote class="wp-block-quote"><p>This is inside the blockquote</p></blockquote>
    <p>And this should be outside!</p>
    </div><!-- .entry-content -->

    You may have other code from your theme or a plugin that’s corrupting the HTML. Since you’ve found a workaround, it may not be worth trying to address the root cause.

    Thread Starter cxtinac

    (@cxtinac)

    Thanks @bcworkz

    The posts were imported using the WordPress importer plugin, exported from an older WordPress 4.7 (from memory) site using the WordPress export. Here’s an example of the first few chars of an exported post content XML section:
    <content:encoded><![CDATA[<blockquote><em><p>February 14th is Valentine’s Day, the one time of the year dedicated [...content skipped...] you.</p></em></blockquote>[...remainder of content...]
    The imported content for the post reflects exactly this unchanged.

    If I display that same post using the following (the complete single.php):

    <?php
    	if ( have_posts() ) :
    			/* Start the Loop */
    			while ( have_posts() ) : the_post(); ?>
    				<h2><?php the_title(); ?></h2>
    				<div id="post-<?php the_ID(); ?>">
    					<div><?php the_content(); ?></div>
    				</div>
    			<?php endwhile;
    	endif;

    I get:

    <div id="post-684">
    <div><blockquote><em><p>February 14th is Valentine?s Day, the one time of the year dedicated..[skip].. you.</p></em> [...remainder of post content skipped here....] your options.</em></p><p>&nbsp;</p></blockquote>
    </div>
    </div>

    -note blockquote at the end of the full content.

    If I enabled the filter the blockquote section is terminated correctly.

    As you say, it is probably not worth chasing very hard (I have not tried on a fresh install for example) – but with such a simple template and simple test case it’s hard to see what’s mangling it.

    Thanks again

    Moderator bcworkz

    (@bcworkz)

    My initial effort involved pasting content into a new post via the code editor. Should be equivalent, but now I tried replicating the issue via actual export/import and am still not seeing any such issue, blockquote tag positioning remains correct.

    If the behavior remains with the default theme and no plugins, then a manual update of core files would be in order. Or just keep your filter hack ??

    Thread Starter cxtinac

    (@cxtinac)

    Fair enough, thanks.
    At some point before too long I might get the chance to test this on a clean empty install – if I do I will report back here what I find (so I won’t close it yet).
    Thanks again ??

    Thread Starter cxtinac

    (@cxtinac)

    UPDATE: Thought I would update anyone still following this, now I’ve had the chance to try the above on a fresh install of 5.9. No plugins except ‘Classic Editor’ and default theme.
    I can confirm that this blockquote behavior is caused by something in my code not the core (as we suspected).

    Thanks for your support @bcworkz

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Intended blockquote tag behavior?’ is closed to new replies.