If your WordPress site is infected with malware, reinstalling WordPress while keeping your content, themes, plugins, and database is the best way to remove the virus. This guide will show you how to reinstall a clean version of WordPress without losing any important data.


Step 1: Backup Your Website

Before reinstalling WordPress, create a full backup to prevent data loss.

Backup Your Files

  1. Use an FTP client (FileZilla) or File Manager in cPanel.
  2. Download the wp-content folder (contains themes, plugins, and media uploads).
  3. Save a copy of wp-config.php (contains database connection details).

Backup Your Database

  1. Log into phpMyAdmin in your hosting panel.
  2. Select your WordPress database from the left menu.
  3. Click Export > Quick method > SQL format and click Go to download the file.

Step 2: Delete Infected Files

  1. Connect to your hosting via FTP or File Manager.
  2. Delete all WordPress core files except:
    • wp-content folder
    • wp-config.php file
  3. This removes infected WordPress files while keeping your important data.

Step 3: Install a Fresh Version of WordPress

  1. Log in to cPanel and open Softaculous Apps Installer.
  2. Click WordPress > Install Now.
  3. Select the same domain as your old site.
  4. Complete the installation (this will overwrite old core files but keep your database).

Option 2: Install Manually

  1. Download the latest WordPress version from wordpress.org.
  2. Extract and upload all files except wp-content to your website via FTP or File Manager.
  3. Do not overwrite wp-config.php—this file contains your database connection details.

Step 4: Check and Update Database

  1. Log in to phpMyAdmin.
  2. Check if the database is intact and clean.
  3. If needed, reset the database by running:
    UPDATE wp_users SET user_pass = MD5('newpassword') WHERE user_login = 'admin';
    

    (Replace “newpassword” with your new password.)


Step 5: Reinstall Themes and Plugins

  1. Log in to WordPress Admin.
  2. Go to Appearance > Themes and reactivate your theme.
  3. Go to Plugins and reinstall essential plugins (avoid previously infected ones).

Step 6: Scan for Malware and Secure Your Site

✅ Install Wordfence or Sucuri Security to scan for malware.
✅ Enable auto-updates for WordPress core, themes, and plugins.
✅ Install SSL Certificate to protect data (available for free in most hosting plans).
✅ Change all admin passwords and remove unknown users.


Conclusion

By following these steps, you can reinstall a clean WordPress version while keeping your database, themes, and uploads intact. If the issue persists, consider hiring a security expert or using WebHostingPK’s free migration services.

Leave A Comment

more similar articles