14

I know this is already marked 'solved' but just for reference, here's a function which does exactly what you want without having to add any markup to posts. Just put this in your theme's functions.php: add_filter('the_content', 'remove_empty_p', 20, 1); function remove_empty_p($content){ $content = force_balance_tags($content); return preg_replace('#...


13

Simply use CSS p:empty { display: none; }


10

There actually are several ways to handle the Wordpress editor wrapping shortcodes in <p> tags. This code shows probably the simplest way to do it...just a simple and short function you need to drop into your functions.php file. Once you do, no more tags around your shortcodes that are on their own line! function wpex_clean_shortcodes($content){ $...


9

You do not need a plugin to do this. Just add 3 lines of code to the end of the functions.php file in your active theme: remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop' , 99 ); add_filter( 'the_content', 'shortcode_unautop', 100 );


8

Paragraph tags are added upon display, not upon storage. The wpautop() function is added as a filter to the_content. You won't ever see these added paragraph tags in either the visual or HTML editors.


6

Use the_content() not echo get_the_content();. As you can see in wp-includes/default-filters.php wpautop is added for the filter 'the_content' which is called in the_content().


6

I guess you don't use it at all, so why don't you just remove the filter? remove_filter('the_content', 'wpautop'); remove_filter('the_excerpt', 'wpautop'); I've tested it a few minutes ago (on WP 4.3) and it works. p.s. I just saw that you use the same function. Sorry for that. What version are you using? This disables the wpautop on 4.3.


6

On the javascript side, as a crude measure you could just replace the wp.editor.autop and wp.editor.removep with no ops: add_action( 'admin_print_footer_scripts', function () { ?> <script type="text/javascript"> jQuery(function ($) { if (typeof wp === 'object' && typeof wp.editor === 'object') { wp.editor....


5

Alright so I've already updated this question a ton and it's starting to get overloaded, so I figured I'd write this as an answer even though it isn't a full one. Extrapolating from @bueltge's answer, I actually went back and found his previous post in question. In that post, there was a plugin listed that I've never seen before: "Preserved HTML Editor ...


4

So, the default xmlrpc get_post function does not have any nice filters for you to use. The solution: roll your own XML-RPC callback! Hook into xmlrpc_methods and add a custom method, in this case called post_autop. The array key will be the method name, and the value the method callback. <?php add_filter( 'xmlrpc_methods', 'wpse44849_xmlrpc_methods' ...


4

One solution is to install the TinyMCE Advanced plugin. In the plugin settings you have a option "Stop removing the <p> and <br /> tags when saving and show Them in the HTML editor".


4

Same approach than 2 answers before me, but an updated regex, because his didn't work for me. the regex: /<p>(?:\s|&nbsp;)*?<\/p>/i (non capture group looking for any number of either whitespace or &nbsp;s inside p-tag, all case insenstive. add_filter('the_content', function($content) { $content = force_balance_tags($content); ...


4

shea's answer is a nice solution, but it turns off autop for all shortcodes which may not be desired. I wrote a script that allows you to run the following: include "shortcode-wpautop-control.php"; chiedolabs_shortcode_wpautop_control(array('yourshortcode')); It allows you to turn off wpautop for specific shortcodes instead of all of them. Once again, I ...


4

Here's the full solution. First disable wpautop in your functions.php remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); Then parse your content/excerpt with nl2br (a standard PHP function). add_filter( 'the_content', 'nl2br' ); add_filter( 'the_excerpt', 'nl2br' );


3

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 ...


3

I have done extended research and found the answer - I am now using a hook on 'tiny_mce_before_init'. Based on other answers (special thanks to answer #2 @Chip Bennett), I have used the following code in my functions.php to secure the paragraph breaks (in the editor HTML mode they show as &nbsp but become paragraphs on the front-end): function ...


3

Yep, it's a total pain. 99% of the 'disable wpautop' tutorials completely miss the tab switch event. Anyway, you should try my plugin - http://wordpress.org/extend/plugins/preserved-html-editor-markup/ Not only will it protect your markup from being mangled by wpautop, but it will preserve line breaks and indentation while still allowing you to use both ...


3

Don't use the_excerpt() if you want to have line-breaks ;)


3

At first, I think this problem was solved since WP version 3.5; see ticket 19666 in trac. But the tinyMCE have a hook there give us the chance to change the content inside the editor and you must not parse on output on frontend. A small source script. I have no test this with a current WP version, was a older solution for a customer. Add this source via ...


3

So, I realized I was using the actual object in the template to call the description $product-get_description(). If you're experiencing this issue, then you can wrap this in a wpautop(), or you can do what WC actually does (not sure how I didn't remember) and use the simple the_content() function to get the description. That will wrap any line breaks in your ...


2

I also needed a way to do this but wasn't happy with any existing solutions so decided to make one. Hope it helps someone. <?php /** * Replaces paragraph elements with double line-breaks. * * This is the inverse behavior of the wpautop() function * found in WordPress which converts double line-breaks to * paragraphs. Handy when you want to undo ...


2

First things first, modifying core files is extremely frowned upon you will have to make these changes with every upgrade and they can lead to security and other problems. I'm pretty sure there is a plugin that will allow this. I did a simple search and here are a few to try: http://wordpress.org/extend/plugins/preserved-html-editor-markup/ http://...


2

Greedy and Ungreedy modifier: preg_replace( '/<p>(.+)<\/p>/Uuis', '$1', $content ); Tested with this script: <?php $c = array(); $c[] = '<p>text</p>'; $c[] = '<p><div>text</div></p>'; $c[] = '<p><div><div>text</div></div></p>'; foreach ( $c as $content ) { $e = ...


2

Add a priority to push your function to the end of the hook queue. add_action('the_content', 'my_plugin_content_hook', 1000); Then, in your get_special_content function you will need to apply wpautop manually to the content to which you want it applied. function get_special_content() { $text = ''; $autopeed = 'content to autop'; $text .= ...


2

You could probably achieve this with a filter of some sort on the_content. Here's a quick and dirty example that finds all instances of <p> and inserts a named anchor, then adds a list of links to each anchor at the top of the content. Check out the Shortcode API as well, which could similarly allow you to add arbitrary sections with text by adding a ...


2

Please try this $c = get_the_content(); instead of: $c = the_content(); since the_content() will echo the content instead of returning it. Or try this <section class="post-content clearfix" itemprop="articleBody"> <?php add_filter( 'the_content', 'wpautop' ); ?> <?php the_content(); ?> <?php remove_filter( '...


2

If what you want is really only to prevent Wordpress from adding empty <p></p> and you'd be happy with removing those after post retrieval from the database, then function wpse108194_remove_empty_paragraphs( $content ) { $content = preg_replace( '#<p>\s*</p>#', '', $content ); return $content; } add_filter( 'the_content', '...


2

This is actually an example of the wpautop() function's intended purpose. From the Codex: Changes double line-breaks in the text into HTML paragraphs (<p>...</p>). Note that the example provided in the Codex explicitly uses a string that begins with a line-break for this very purpose: <?php $some_long_text = // Start Text Some long text ...


2

It seems the function is broken. The issue is in trac: https://core.trac.wordpress.org/ticket/14050 I am using this to solve the problem temporarily: https://core.trac.wordpress.org/attachment/ticket/14050/plugin.php . This code still fails some of the tests used, but it completely resolves the issue I described, so I will use it unless I find something ...


2

I think it's safe to say that wpautop() is a basket case without hurting anyone's feelings, but I wouldn't remove & add it at a different priority as that just makes things worse, as demonstrated (although what you posted is the browser trying to make sense of broken html, rather than the actual output, which does only have the <a> tag once). To ...


Only top voted, non community-wiki answers of a minimum length are eligible