Content editor creating blank paragraphs in spaces and creating &nbsp in the_excerpt

by Gabriel Souza   Last Updated February 24, 2017 20:08 PM

I see that in other sites that use wordpress this does not happen, so I would like to know how to space without creating a blank paragraph or a &nbsp ?

As you can see in the image, in each space a blank paragraph is created

enter image description here

And in the_excerpt too

enter image description here

My site if you want to see more examples



Answers 2


<?php
function add_necessary_functions() {

    function read_more($limit){
        $post_content = explode(" ", get_the_content());
        $less_content = array_slice($post_content, $limit);
        echo implode(" ", $less_content);
    }
}
add_action("after_setup_theme","add_necessary_functions");
?>

You Can create your won read more function with this. And use $limit as the counter that how many word you want to display.

Morshed Maruf
Morshed Maruf
February 24, 2017 19:48 PM

Judging from your site's content and the comments, you may try using the following CODE in your theme's functions.php file. It'll remove empty <p>&nbsp;</p> tags from post content:

add_filter( 'the_content', 'wpse_257854_remove_empty_p', PHP_INT_MAX );
add_filter( 'the_excerpt', 'wpse_257854_remove_empty_p', PHP_INT_MAX );
function wpse_257854_remove_empty_p( $content ) {
    return str_ireplace( '<p>&nbsp;</p>', '', $content );
}

However, after it removes the empty <p>&nbsp;</p> tags, paragraphs in your site's post content will collapse with each other. To maintain the visual gap between paragraphs, you may use the following CSS:

.conteudo-noticia p {
    padding-bottom: 15px;
}

If nbsp; within meta description tags are coming from content (or excerpt) & the plugin used to capture them are handling the content as it should (according to WordPress loop standard), then after using the above CODE, meta tags should be fixed as well.

Note: After making the above changes, please make sure you clear browser cache properly and clear any server cache (from cache plugin, web server etc.) if present before testing the result.

Update:

If you don't want to control paragraph gap with CSS padding, then there is a slightly different CODE you may try:

add_filter( 'the_content', 'wpse_257854_remove_empty_p', PHP_INT_MAX );
add_filter( 'the_excerpt', 'wpse_257854_remove_empty_p', PHP_INT_MAX );
function wpse_257854_remove_empty_p( $content ) {
    return str_ireplace( '<p>&nbsp;</p>', '<br>', $content );
}

This CODE, instead of removing the empty p tags, replaces them with line breaks <br>. So this way you can control paragraph gaps from within the editor without having empty p tags with &nbsp;.

Fayaz
Fayaz
February 24, 2017 23:22 PM

Related Questions


Stop Wordpress Wrapping Images In A "P" Tag

Updated August 11, 2018 22:08 PM


data-accordion removed in Visual Editor

Updated May 15, 2015 22:03 PM