admin管理员组

文章数量:1318988

Here's what I'm trying to do:

Page URL: /

What it should load: .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 .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?

Here's what I'm trying to do:

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

What it should load: https://example/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/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?

Share Improve this question asked Oct 16, 2020 at 18:57 JakeJake 5501 gold badge6 silver badges24 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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;
}

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/landing/. There are many ways to upload files to your hosting. You can use a standalone file manager (e.g. Total Commander or FileZilla).

本文标签: customizationHow To Load an HTML File As A WordPress Page (With No 301No Redirect)