WPHammer
Log in
  • How it works
  • Safety
  • Related
  • Search & Replace

    WPHammer provides a database search and replace tool for WordPress sites, powered by the wp search-replace WP-CLI command. This is essential for domain migrations, protocol changes, and any situation where you need to update URLs or strings stored across the WordPress database.

    Common use cases

    Domain migration

    When moving a WordPress site to a new domain, the database contains thousands of references to the old domain — in post content, options, widget settings, and serialized data. Search and replace updates all of these in a single operation.

    Example: replacing https://old-domain.com with https://new-domain.com across the entire database.

    HTTP to HTTPS

    After enabling SSL on a site, internal links and embedded resources may still reference http:// URLs. A search and replace from http://example.com to https://example.com resolves mixed-content warnings.

    Staging to production

    When pushing a staging site to production (or pulling production data to staging), the domain stored in the database needs to change. Search and replace handles this as part of the staging workflow.

    Fixing hardcoded paths

    Occasionally WordPress sites contain hardcoded file paths or URLs from a previous server environment. Search and replace can update these references in bulk.

    How it works

    When you run a search and replace operation:

    1. WPHammer connects to the server via SSH.
    2. The wp search-replace command is executed against the site's database.
    3. WP-CLI handles serialized data correctly — it unserializes values, performs the replacement, and re-serializes without corrupting the data.
    4. The operation reports how many replacements were made across which tables.

    The command runs in the context of the site's WordPress installation, using the database credentials from wp-config.php.

    Safety

    Search and replace is a powerful operation that modifies database content directly. A few things to keep in mind:

    • Back up first — always ensure you have a recent backup before running a search and replace, especially on production sites
    • Review the scope — the operation runs across all WordPress database tables by default
    • Serialized data — WP-CLI's search-replace command is serialization-aware, so it safely handles options, widget settings, and other serialized values that SQL REPLACE would corrupt
    • Dry run — consider running a dry pass first to see how many replacements would be made before committing the changes

    Related