Last active
          March 6, 2025 19:13 
        
      - 
      
- 
        Save khleomix/b0fc46a6b0d24ddea69e6bc8abca7833 to your computer and use it in GitHub Desktop. 
Revisions
- 
        khleomix revised this gist Mar 6, 2025 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php function replace_nbsp_in_posts() { global $wpdb; 
- 
        khleomix created this gist Mar 6, 2025 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ function replace_nbsp_in_posts() { global $wpdb; $query = " UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, CHAR(160), ' ') WHERE post_content LIKE '%" . chr(160) . "%' "; $result = $wpdb->query($query); if ($result !== false) { return "Successfully replaced non-breaking spaces in $result posts."; } else { return "Failed to update posts."; } } // Run the function only when needed add_action('admin_init', function() { if (current_user_can('manage_options') && isset($_GET['replace_nbsp'])) { echo '<div class="updated"><p>' . replace_nbsp_in_posts() . '</p></div>'; } });