Tag Info

Hot answers tagged

11

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!


8

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


6

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


5

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


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

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


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

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

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


4

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


4

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.


4

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


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

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


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

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

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

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


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

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

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


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


1

Well, removing autop filter from the_content filter tag makes no sense here, because you never apply the_content filters in your code... Let's take a look at the source code of the_content() function: function the_content( $more_link_text = null, $strip_teaser = false) { $content = get_the_content( $more_link_text, $strip_teaser ); $content ...


1

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


1

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). <?php echo nl2br(get_the_content()); ?>


1

The extra space comes from wpautop(), which inserts <br /> on every line break. You have to strip these out before calling do_shortcode(). Additionally, use add_filter( 'the_content', 'shortcode_unautop' );. From my experience, you need both. Probably a bug. See my shortcode plugin for an example. It has shortcodes for tables too. Aside: Shortcodes ...


1

Try this: // replaces [banner ...] .. [/banner] with <!--banner ID--> before the_content filters run add_filter('the_content', 'protect_my_shortcode', -100); function protect_my_shortcode($content){ return preg_replace_callback('/\[(banner)\b(.*?)(?:(\/))?\](.+?)\[\/\1\]/s', 'protect_my_shortcode_callback', $content); } function ...


1

You either need to add such code via the HTML editor (and not switch back to the Visual editor), or else you will need to pass a custom configuration to the Visual editor. I have similar needs, and here's what I use (in functions.php): // http://tinymce.moxiecode.com/wiki.php/Configuration function cbnet_tinymce_config( $init ) { // Change code ...



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