Streaming live at 10am (PST)

Remove Empty Lines at end of Rich Text Blocks in CMS

I’m not sure why the CMS does this but it often leaves an empty paragraph at the end of a rich text block when editing in the CMS - and almost always when pasting in content into a Rich Text Block - (I use Windows so maybe that’s it).

This piece of code will remove them empty paragraphs. Particularly useful when clients are using the CMS as they will often leave some empty lines there without noticing

    // REMOVE EMPTY LINES AT END OF RICHTEXT
  	$(".w-richtext p").each(function(){
        if ($(this).text().length < 2){
            $(this).text(function() {
                return $(this).text().replace(/(^[\s\u200d]*$)/g, 'removeEmptyParagraph');   
            });
        }
    });
	$("p:contains('removeEmptyParagraph')").remove();
1 Like