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 badges2 Answers
Reset to default 2You 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)
版权声明:本文标题:customization - How To Load an HTML File As A WordPress Page (With No 301No Redirect) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742055014a2418240.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论