Tag Info

Hot answers tagged

8

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!


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

WordPress will automatically insert <p> and </p> tags for you to 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 follow code bits. To disable completely this autop filter you can use: remove_filter('the_content', 'wpautop'); and if you still want this to function ...


4

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


4

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


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

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


3

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


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

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

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


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

Generally it's not a common way to strip wpautop with remove_filter as it is native functionality of WordPress. But if you want to : place the remove_filter() function right before the the_content() function on the pages/templates where you don't need the wpautop <?php remove_filter( 'the_content', 'wpautop' ); the_content();?>


1

Manipulating HTML with regular expressions is not a good idea. I suggest you use DOMDocument: // input $html = apply_filters('the_content', get_the_content()); $dom = new \DomDocument(); $dom->loadHtml($html); $blockquotes = $dom->getElementsByTagName('blockquote'); foreach($blockquotes as $blockquote){ foreach($blockquote->childNodes as $e){ ...


1

Ok, I've never seen a shortcode done in this way so I threw together a bit of code to test your scenario. And I get the same results with code that works just fine with the standard shortcode format. Standard Shortcode Format [shortcode name1="value1" name2="value2"] I don't believe this is a result of wpautop(), but a result of the way the shortcode ...


1

Here is one idea add_filter('the_content','remove_stuff',99,1); function remove_stuff($content){ $from=array("<p><script>","</script></p>"); $to=array("<script>","</script>"); $content=str_replace($from,$to,$content); return $content; }


1

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


1

A blockquote is a block element, and shouldn't be put inside a <p> tag, what you're seeing is your browsers DOM trying to compensate for the invalid html markup. If you look at the raw source code itself generated, you will not find those stray paragraph tags Remove your <p> wrapping tags, and make sure any content that needs wrapping in a ...


1

There is my solution - tehere is my solution of this problem: Preserving tabs and line breaks in <pre><code> when switching from HTML to Visual Editor


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


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

Jared's answer will get you the auto paragraph tags. But a more complete solution might be to run the the_content filter on your text with apply_filters. This will run the following functions on your text: wptexturize, convert_smilies, convert_chars, wpautop, shortcode_unautop, prepend_attachment. I believe it'll also run do_shortcodes for you. So that'll ...



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