Hot answers tagged

13

I had the same problem you have. I just did a... let's say... not very beautiful solution, but it works and so far it's the only solution I have. I added a little JavaScript line. It needs jQuery, but I'm sure you can figure it out without. This is my tiny JS: $('p:empty').remove(); This works for me!


12

WordPress will automatically insert <p> and </p> tags which separate content breaks within a post or page. If, for some reason, you want or need to remove these, you can use either of the following code snippets. To completely disable the wpautop filter, you can use: remove_filter('the_content', 'wpautop'); If you still want this to function ...


9

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('#...


8

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){ $...


7

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

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 );


6

I just ran into this situation. Here is a function I used to undo wpautop. I might be missing something, but this is a good start: function reverse_wpautop($s) { //remove any new lines already in there $s = str_replace("\n", "", $s); //remove all <p> $s = str_replace("<p>", "", $s); //replace <br /> with \n $s = ...


5

You could just run your filter before that nasty wpautop hooks on and messes with the markup. add_filter('the_content', 'qanda', 7 ); That way, you've already converted what you need to by the time it hooks on, which does help in some cases.


5

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


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

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


4

Add a function that grabs your meta data, applies wpautop and echoes it out, or otherwise run it through when you output it in your template. $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); echo $my_meta['name']; echo wpautop( $my_meta['description'], 1 );


4

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.


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

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

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

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


2

The filter write not in the database, filter on frontend, when view the post or other content. You deactivate the filter and write a own filter for set your custom markup.


2

Take a better look at the arguments that this functions accepts: wp_link_pages(array( 'before' => 'Pages', 'after' => '', ));


2

That's 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 wrote the ...


2

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


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

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' );


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



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