I have wordpress installed in root folder of domain.com

I want to load index.html when domain.com is visited and domain.com/my-posts/ should load normal wordpress posts.

I am doing this to increase speed of my wordpress homepage.I dont want any php to be involved.

Will renaming index.php to index.html and putting my html content will work ?

  • 5
    A more constructive answer is to have this file somewhere and add a rewrite rule that will serve it when the home page is requested/ Place that rule before the wordpress rules – Mark Kaplun Mar 13 at 5:40
  • 1
    You'd do that with a page-template: developer.wordpress.org/themes/template-files-section/… – admcfajn Mar 13 at 6:14
  • Question is not silly , What if i need custom html landing page using bootstrap as homepage ? AndI dont want 1.3 mb page to load :p – Gracie williams Mar 13 at 20:13
  • 1
    Gracie, PHP runs on the server and is one of the very least concerns for page speed optimization. A thousand lines of PHP code could execute in the time it takes a browser to request a single image asset for your page. Unless your situation is an edge case of some kind, the performance benefit to be gained here is not worth your effort IMO. – jdm2112 Mar 14 at 13:51
  • @Graciewilliams, if you use bootstrap, it will take much more time in vanilla HTML to load all the assets of bootstrap than for wordpress running on a proper server configuration to generate the page dynamically, and if you care about performance you will use CDN, which means that you already have caching. Anyway, landing page is a great example why it is wrong, aren't you going to want to use a plugin for that page (SEO, contact form, etc), are you realy going to "manually" change every little thing when needed instead of using the power of a CMS? – Mark Kaplun Mar 14 at 18:42

I strongly advise you to heed the advice already given. If your PHP is well structured and you take advantage of caching methods, it won't have a significant increase on your page load time. We've got pages with extremely complex queries that are hardly optimized, but using some clever caching methods, we're able to get those pages served in 500-900ms, or 2-3s for some of the much more complex pages.

It's a much better long term solution than using a static HTML page as your homepage.

That said - if you still wish to proceed with a static HTML homepage instead (again, please don't, especially if the only reason is "page speed", since there are so many other ways to decrease your page load time)

... Still reading?

Method 1: .htaccess

The… 🙄… "generally accepted" way to do this is with a .htaccess rule that targets your homepage only, such as RewriteRule ^$ http://example.com/path-to-html.html [L,R=301]

Method 2: Page Template

Alternatively, to maintain some semblance to the WordPress ecosystem would be to set up a Page Template

  • Add a home.php (yes, PHP file) to your active theme directory: /wp-content/themes/CURRENT-THEME/home.php.
  • Place the following "Page Template Header" code in that file (leave a note to your future self/fellow devs that say where the file is so it's less confusing):

    <?php
        /*
         * Template Name: My HTML Homepage
         */
    ?>
    <!-- This page is generated outside of WP by: /wp-content/themes/CURRENT-THEME/home.php -->
    <!-- Your HTML Code Here -->
    
  • Add a new Page with Pages > Add New with a recognizable name, such as "My HTML Homepage"

  • On the right hand side, in the Template selector, choose "My HTML Homepage" as the template.
  • In Settings > Reading change "Your Homepage Displays:" to "A Static Page", and pick the "My HTML Homepage" page you just added.

Method 3: Move your WordPress Install

You can also just install WordPress on a subdirectory, have index.html in the root directory, and use .htaccess to remove the /wp from your URLs.

Method 4: Don't.

Again, I strongly urge you to consider other methods:

  • Taking advantaged of PHP 7.x and memcache/d
  • Caching plugins like WP Super Cache/W3 Total Cache
  • Optimizing your images (manually or with WP Smush)
    • Serve images from a CDN
  • Optimizing Script/Style delivery (WP Hummingbird can help with this):
    • Combine files where appropriate/able
    • Minify those files
    • Serve those files from a CDN
  • Remove unnecessary plugins from WP, optimize JS functions, remove unused CSS selectors, etc.
  • I have nginx , Wp super cache and total cache is not working fine with it. – Gracie williams Mar 15 at 8:26
  • There are quite a few tutorials and other docs out there on setting up WPSC with Nginx. Alternatively you could also consider a PHP plugin like PHPFastCache. Also, make sure you're taking advantage of the WP Transients API, especially for expensive queries. – Xhynk Mar 15 at 16:23

If your concern is that PHP or MySQL is causing the page load speed to decrease, I recommend installing a Caching plugin and configuring Page Caching. A free plugin that I've used for this purpose is W3 Total Cache

Page caching essentially does what you are looking for, which is to serve a static HTML file with CSS and Javascript assets, instead of running PHP and MySQL queries whenever a page is loaded.

It does this by pre-generating each page as a static HTML file, and then serves those static files in place of the dynamic PHP / MySQL Wordpress engine.

It's much easier to set up than having to manage a separate static HTML file for your landing page.

  • 1
    side note: from my experience W3TC is an undebuggble POS. I get it that you had better mileage with it then me, but I felt the need to drop here a note that there are other plugins that might be better – Mark Kaplun Mar 14 at 18:46
  • its not working fine for me in nginx , same speed in pagespeed insights – Gracie williams Mar 16 at 20:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.