How to Bulk Replace Text in WordPress

Migrating a website from one domain to another is a task many website owners face. One of the most common issues during such migrations is leftover mentions of the old domain within the site’s content. These can significantly affect SEO performance and user experience. In such cases, a bulk text replacement is required — and WordPress offers several ways to do this.

Methods for Bulk Text Replacement in WordPress

Using code in the functions.php file:

For temporary text replacements, you can use custom functions inside your theme’s functions.php file. This method doesn’t modify the database, and once the code is removed, all changes are automatically reverted. For example:

// Массовая замена текста
function replace_text($text) {
$text = str_replace('old-domain.com', 'new-domain.com', $text);
return $text;
}
add_filter('the_content', 'replace_text');
Dima
Dima
Задать вопрос
This code will replace all mentions of old-domain.com with new-domain.com when the page loads. This approach works well for temporary or testing changes. However, you’ll need to keep this code in place, as the replacement happens dynamically during each page load.

замена текста в WordPress

Using Plugins

For permanent data replacement in the database, you can use specialized plugins such as Better Search Replace or Word Replacer. These tools provide a graphical interface for safely modifying database content, support data backups, and allow you to undo changes if needed.

Manual Editing via phpMyAdmin

If you’re confident in your database management skills, you can use phpMyAdmin to run SQL queries for text replacement. This method is more advanced and carries higher risk, as it requires precision and a good understanding of your database structure.

Example SQL query:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'old-domain.com', 'new-domain.com');

By applying these methods and following the recommendations, you can efficiently update data on your WordPress site after changing the domain, minimizing potential issues and ensuring a smooth experience for your users.

Оцените статью