I have a shortcode for a blockquote [blockquote]this is the quote[/blockquote] … this is the code.

function shortcode_shortcodetest( $atts, $content = null ) {
    $return = '<div class="blockquotewrapper"><blockquote>';
    $return .= do_shortcode( $content );
    $return .= '</blockquote>';
    $return .= '</div>';
    return $return;
}
add_shortcode( 'shortcodetest', 'shortcode_shortcodetest' );

so I would be expecting an output of:

<div class="blockquotewrapper">
<blockquote><p>this is a test</p></blockquote>
</div> 

or maybe

<div class="blockquotewrapper">
<blockquote>this is a test</blockquote>
</div>

but what I get is:

<div class="blockquotewrapper">
<blockquote>this is a test<p></p></blockquote>
</div>

( note posision of opening paragraph tag )

What is causing the opening p tag to move to where it does. I have noticed that if I remove either the div or blockquote from the shortcode function then it doesn’t happen, but I wanted to have the wrapper for some styling reasons and because in the full version I have an associated cite possibility … and obviously I need to have the blockquote.

2 Answers
2

By chance I just happened to discover what it was, so I think I’ll leave this here as it might help someone in the future.
Some web pages, including an answer to this question suggest using the following code to prevent wpautop from running until after the shortcodes. Now I wasn’t able to fully understand this code, but I had it in my functions.php and for whatever the reason it was the cause of the above.

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12);

Leave a Reply

Your email address will not be published. Required fields are marked *