Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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);
share|improve this answer

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?

?>

output some html here....               (one line end here)
                                        (one line end here)
<?php
some other functions here...

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.