Back to Top

What is Wpautop() function in WordPress

Wpautop() function in WordPress

WordPress is the best solution for many of bloggers and site builders because it provides a flexible, extendable, and quick way to build robust websites that non-technical person could manage on their own.

About Wpautop() function

The wpautop function is used to automatically formats posts in WordPress.Wpautop is especially used to automatic formatting a paragraph.Wpautop filter which will change double line breaks into paragraph tags.Whenever you add content using TinyMCE editor and add a new line then will create a double line break which might not look better so this filter solves this problem.

First of all, Let’s understand wpautop if you are confused about what this function does and how to use it.

For example, you have typed following line of code into visual editor on a post

I like creativedev.
It is a very nice blog.

Output:

I like creativedev.

It is very nice blog.

Read: To add new URL rewrite rule in WordPress

Here, I am going to share function which is used to reverse the Wpautop functionality in WordPress.

function reverse_wpautop( $string = '' ) {
    
    /* return if string is empty */
    if ( trim( $string ) === '' )
      return '';
      
    /* remove all new lines & 

tags */ $string = str_replace( array( "\n", "

" ), "", $string ); /* replace
with \r */ $string = str_replace( array( "
", "
", "
" ), "\r", $string ); /* replace

with \r\n */ $string = str_replace( "

", "\r\n", $string ); /* return clean string */ return trim( $string ); }

This function is used to reverse the effect of wpautop() function.Permanently removing wpautop is not useful every time so you can use this function and call when you want for turning reversing the “p” and “br” tags to newlines. It will check p and br tags and replaces with the newline character, provides the clean string to you.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use Interface in PHP

Posted on 7 years ago

Bhumi

How to get the host name of user in PHP

Posted on 7 years ago

Bhumi

PHP 5 Abstract classes and Methods

Posted on 7 years ago

Bhumi

How To set up Signup Bonus in X-Cart

Posted on 7 years ago

Bhumi

Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago

Bhumi

ECMAScript 6 New Features – 2

Updated 1 year ago

Bhumi

The Reader’s Poll – June 2015

Posted on 4 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 5 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 6 years ago

Bhumi