/*
Theme Name: Highend Child
Theme URI:  https://www.wpserveur.net
Author:     WPServeur
Author URI: https://www.wpserveur.net
Template:   HighendWP
Version:    1.0
License:    GNU General Public License v2 or later
/**
 * Limpia <br> forzados y &nbsp; en el contenido
 */
function ocdtech_clean_content_format( $content ) {
  // 1) Reemplaza &nbsp; por espacio
  $content = str_replace( '&nbsp;', ' ', $content );

  // 2) Elimina todos los <br> o <br /> extras
  $content = preg_replace( '#(<br\s*/?>\s*)+#i', '', $content );

  return $content;
}
add_filter( 'the_content', 'ocdtech_clean_content_format', 20 );
<?php
/**
 * Clean up forced <br> tags and non‑breaking spaces from post content
 */
function ocdtech_clean_content_format( $content ) {
    // 1) Replace all &nbsp; with a normal space
    $content = str_replace( '&nbsp;', ' ', $content );

    // 2) Remove any <br> or <br /> occurrences
    $content = preg_replace( '#(<br\s*/?>\s*)+#i', '', $content );

    return $content;
}
// Hook it into the_content at priority 20
add_filter( 'the_content', 'ocdtech_clean_content_format', 20 );
<?php
/**
 * Clean up forced <br> tags and non‑breaking spaces
 * from both post content and excerpts.
 */
function ocdtech_clean_formatting( $text ) {
    // 1) Replace all &nbsp; with a normal space
    $text = str_replace( '&nbsp;', ' ', $text );
    // 2) Remove any <br> or <br /> occurrences
    $text = preg_replace( '#(<br\s*/?>\s*)+#i', '', $text );
    return $text;
}
// Apply to the full content
add_filter( 'the_content',       'ocdtech_clean_formatting', 20 );
// Apply to the excerpt when displayed
add_filter( 'the_excerpt',       'ocdtech_clean_formatting', 20 );
// Apply to the raw excerpt value (get_the_excerpt)
add_filter( 'get_the_excerpt',   'ocdtech_clean_formatting', 20 );
<?php
/**
 * Inject front‑end JS to remove stray <br> and &nbsp; in posts & excerpts.
 */
function ocdtech_cleanup_br_nbsp_js() {
    // Only load on the front end
    if ( is_admin() ) {
        return;
    }
    ?>
    <script>
    document.addEventListener('DOMContentLoaded', function() {
      // Adjust these selectors if your theme uses different wrappers:
      var targets = document.querySelectorAll('.entry-content, .entry-excerpt');
      targets.forEach(function(el) {
        // 1) Remove all <br> tags
        el.querySelectorAll('br').forEach(function(br){ br.remove(); });
        // 2) Replace all &nbsp; with normal spaces
        el.innerHTML = el.innerHTML.replace(/&nbsp;/g, ' ');
      });
    });
    </script>
    <?php
}
add_action( 'wp_footer', 'ocdtech_cleanup_br_nbsp_js', 999 );
*/