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.
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.
Looking on the codex shows that WordPress automatically changes double line breaks in content into paragraph tags. The code you put into your functions.php will disable this. This will change this on every page on your site.
A better solution might be to check your short code function. It is most likely outputting some white space at the end of its output. Mabey a blank line at the end of the html output before an opening
<?php
tag?What you have will probably work here, but it will change the output of all your pages. I doubt that is what you had in mind.