admin管理员组文章数量:1320661
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 :
/
But i'm wondering : Is there a solution proposed by the wordpress API itself, or something that i am missing here ?
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/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 asked Jun 20, 2011 at 3:34 SpyrosPSpyrosP 5152 gold badges10 silver badges23 bronze badges3 Answers
Reset to default 3The 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
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]
Simple solution which worked for me is to just remove paragraph end "</p>" from the beginning of the $content, and paragraph begin "<p>" from the end of the $content.
For example with regex like:
function fix_paragraphs($content)
{
$patterns = array('/^<\/p>/i', '/<p>$/i');
return preg_replace($patterns, '', $content);
}
Or if you're sure they'll be there, you could just trim them like this:
return substr($content, 4, -3);
本文标签: How can i remove the paragraph from shortcodes content
版权声明:本文标题:How can i remove the paragraph from shortcodes content? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742063792a2418708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论