0

Here's what I'm trying to do:

Page URL: https://example.com/the-page/

What it should load: https://example.com/content/oct2020/index.html

When visitors go to the permalink /the-page/, I'd like that permalink to stay exactly the same. But instead of loading content & template files from the WordPress database, it would just display the index.html file instead.

I do not want someone to visit "/the-page/" permalink, and then be 301'd to https://example.com/content/oct2020/index.html.

I know this can be done with a Page Template, but then I'd need all the files to be inside my WP themes directory. Instead I want to host these HTML files in a separate directory, totally theme-agnostic. Is there a plugin offering this kind of functionality, or would it be easy to code up as a functions.php addon? Or would the easiest solution be adding a line into my .htaccess file?

2

You can use the template_include hook to accomplish this.

Add this to your active theme's functions.php file (or create a plugin).

add_filter( 'template_include', 'wpse376643_load_html_page' );
function wpse376643_load_html_page( $template ) {
    if ( is_page( 'the-page' ) ) {
        // You'll have to use the server path to your index.html file.
        $template = '/path/to/your/content/oct2020/index.html';
    }
    return $template;
}
1
  • 1
    This is the best solution given so far, because it actually addresses my question (ie. the files on my server will not match the URL). I need a way to make the URL be any customized string of characters that I want, even if my server's folder structure does not correlate. Thanks for the response I will try this if it's generally the simplest option
    – Jake
    Oct 18 '20 at 14:21
1

First of all, you need to create a new empty folder in the root folder of your WordPress website. Typically, it is located here: /public_html/. So, the location of our HTML template will be /public_html/landing/, where ‘landing’ is the name of the folder with our template. The page will be available at http://www.domain.com/landing/. There are many ways to upload files to your hosting. You can use a standalone file manager (e.g. Total Commander or FileZilla).

4
  • 1
    The 'better way' here is the correct answer. I'd edit out the Elementor reference because OP wants the HTML to be theme agnostic/independent. Oct 17 '20 at 1:55
  • Thank you will edit it Oct 17 '20 at 8:44
  • This answer is the correct way. It'll be quicker to load than my template_include solution, because the file at {site root}/the-page/index.html won't have to load WordPress prior to displaying anything.
    – Pat J
    Oct 17 '20 at 16:39
  • @PatJ @Tony This is not a solution to my specific question. In my example the files are located at /content/oct2020/, however that cannot be the URL. So I need a way to customize the URL to be anything(ex: "/my-page-here/") but the files cannot be located in a folder on the server literally titled "my-page-here".
    – Jake
    Oct 18 '20 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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