Skip to content

Instantly share code, notes, and snippets.

@raihan004
Forked from MichaelVanDenBerg/remove-empty-p.js
Created April 14, 2018 09:09
Show Gist options
  • Save raihan004/971aa20b7ca28098b790468f8383320b to your computer and use it in GitHub Desktop.
Save raihan004/971aa20b7ca28098b790468f8383320b to your computer and use it in GitHub Desktop.
Remove empty <p> tags with jQuery.
/**
* Remove empty <p> tags.
*
* See: http://stackoverflow.com/questions/27781798/wordpress-retain-formatting-when-calling-extended-content#comment43990361_27782619
* This seems to be the easiest solution. Remove this function if this ever gets fixed.
* Credits: http://stackoverflow.com/questions/6092855/how-do-i-remove-empty-p-tags-with-jquery
*/
( function( $ ) {
$( 'p' ).each( function() {
var $this = $( this );
if ( $this.html().replace( /\s|&nbsp;/g, '' ).length === 0 ) {
$this.remove();
}
});
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment