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 '
' . replace_nbsp_in_posts() . '