Introduction

The index.php file is one of the main core files of a WordPress website. It is located in the WordPress root directory and is responsible for loading the WordPress environment and theme. When a visitor opens the website, this file helps WordPress load the required files and display the website properly.

Sometimes, the index.php file may be modified, corrupted, deleted, or infected due to malware or website hacking. If the WordPress index file is hacked or damaged, the website may show a blank page, redirect to another website, display unwanted content, or stop loading completely.

This guide explains how to restore the default WordPress index.php file safely.

Prerequisites

Before restoring the WordPress index.php file, make sure you have the following:

  1. cPanel, FTP, SSH, or File Manager access.
  2. Access to the WordPress website root directory.
  3. Backup of the current website files.
  4. Basic knowledge of WordPress file structure.
  5. Permission to edit or replace the index.php file.
  6. Malware scan report, if the website was hacked.
  7. Latest clean WordPress core files for reference.

Implementation Steps

Step 1: Log in to cPanel or Server

Log in to your hosting control panel, cPanel, FTP, or SSH.

If you are using cPanel, open:

cPanel → File Manager

Step 2: Open the WordPress Root Directory

Go to the WordPress installation directory.

Common WordPress root paths are:

/public_html
/public_html/domain.com
/home/username/public_html

You should see files like:

index.php
wp-config.php
wp-blog-header.php
wp-admin
wp-content
wp-includes

Step 3: Take a Backup of the Existing index.php File

Before making any changes, download or rename the existing index.php file.

Example:

index.php-old

This helps you keep a copy of the previous file for checking or investigation.


Step 4: Check Whether index.php Is Hacked

Open the existing index.php file and check for suspicious code.

A hacked WordPress index.php file may contain:

base64_decode
eval
gzinflate
shell_exec
iframe
unknown script URLs
automatic redirect code

If you find suspicious code, the file should be replaced with the default WordPress index file.


Step 5: Replace with the Default WordPress index.php Code

Create or edit the index.php file and add the below default WordPress code:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
?>

Save the file after updating the code.


Step 6: Set Correct File Permission

Make sure the index.php file has the correct permission.

Recommended permission:

644

If you are using SSH, you can run:

chmod 644 index.php

Step 7: Clear Website Cache

After restoring the file, clear all caches.

Clear cache from:

WordPress cache plugin
Server cache
Browser cache
CDN cache
Cloudflare cache, if used

Step 8: Test the Website

Open the website in a browser and confirm that it is loading properly.

Also check:

Homepage
Admin login page
Inner pages
Posts
Contact form

WordPress admin login URL:

https://yourdomain.com/wp-admin

Step 9: Scan the Website for Malware

If the index.php file was hacked, scan the full website because the same malware may exist in other files also.

Check important folders:

wp-admin
wp-content
wp-includes
plugins
themes
uploads

You can also check recently modified files from SSH:

find . -type f -mtime -7

This command shows files modified in the last 7 days.


Step 10: Update WordPress Core, Themes, and Plugins

After restoring the file, update WordPress and all plugins/themes to reduce security risk.

Update:

WordPress core
Themes
Plugins
PHP version
Security plugin rules

Remove unused themes and plugins if they are not required.

Conclusion

The WordPress index.php file is a core file required to load the WordPress website. If this file is hacked, modified, or deleted, the website may stop working or show unwanted redirects and malicious content.

By replacing the infected or corrupted index.php file with the default WordPress code, the website can be restored quickly. However, replacing only the index.php file is not enough if the website was hacked. A full malware scan, plugin/theme update, and security review should also be completed to prevent the issue from happening again.

Leave a Reply