Last active
March 6, 2025 19:13
-
-
Save khleomix/b0fc46a6b0d24ddea69e6bc8abca7833 to your computer and use it in GitHub Desktop.
Remove nbsp
This file contains 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 characters
<?php | |
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>'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment