-
-
Save tw2113/c14fac4a6c180ef77b2e72bc2cdaa2f1 to your computer and use it in GitHub Desktop.
Remove nbsp
This 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 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