Call Us : +1-678-551-2452
+91 77381-86899

Remove

 

Empty p tags from wordpress post / page content

 

Empty p tags from wordpress post / page content

Adding content in wordpress editor might add empty p tags which contains only   or nothing

which will cause extr line break while visually viewing the post on the front end . Below is the solution to the problem.

1. Remove empty p tags such as <p> </p> .

add below code to css

p:empty {
display: none !important;
}

2. Remove  p tags which contains &nbsp;  such as <p> &nbsp;  </p> .

add below filter at the end of the functions.php file of the theme.

add_filter(‘the_content’, ‘remove_empty_tags_p’, 20, 1);
function remove_empty_tags_p ($str, $repto = NULL) {
$str = force_balance_tags($str);
//** Return if string not given or empty.
if (!is_string ($str)
|| trim ($str) == ”)
return $str;

//** Recursive empty HTML tags.
return preg_replace (
‘~\s?<p>(\s|&nbsp;)+</p>\s?~’,

//** Replace with nothing if string empty.
!is_string ($repto) ? ” : $repto,

//** Source string
$str
);}

 

 

Leave a Reply

Pay with PayPal

Icon Web Solutions Service
Other Amount:
Name:

Testimonials

It has been a great pleasure working with Icon Web Solutions on the development of my digitized logo and website. From the initial phases of web design, the Icon Web Solutions team has been a pleasure to work with
Naren, USA

REQUEST A QUOTE

Request A Quote

Please fill the form to request a quote from us

Name (required)

Email (required)

Phone

Services
 Website Design & Development Logo Design SEO SMO Payment Gateway Integration Others

Any Other Detail

Input Text Shown in Image
captcha