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.

If you have created shortcodes in Wordpress, you may have noticed that when you get the content of your shortcode, it's wrapped in html paragraph tags.

I don't know why the progammers did that. It seems like a very bad idea to me to add formatting to the actual content.

I've found a post that presents this solution :

http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/

But i'm wondering : Is there a solution proposed by the wordpress API itself, or something that i am missing here ?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

The shortcodes, since they are inserted in the editor, comply to editor rules. Hitting the return in editor will generate a paragraph tag, just like any other text. It's one of the TinyMCE features. To read more about TinyMCE check out their forum and especially this thread

share|improve this answer
    
ahh, so that is why it happens. thanx :) –  SpyrosP Jun 20 '11 at 4:59
    
also, here's a link to some plugin options allowing you to change the default tinyMCE behaviour / replace the editor: wpmu.org/why-you-hate-the-wordpress-text-editor –  memeLab Aug 28 '12 at 2:17
add comment

The link in you're question is now extinct, so I'm not sure of the solution it suggested, but here's another solution for posterity:

Add the following to functions.php to run the formatting after shortcodes are evaluated:

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

The author notes that you'll need to explicitly enable formatting within plugins that require it:

function my_shortcode($atts) {
    $content = wpautop(trim($content));
    [snip]
share|improve this answer
add comment

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.