From this Stack Overflow qestion It shows a bunch of ways to make page templates. But I don't want to use a page template that uses Gutenberg.
Is there another way to make a PHP file like a tos.php, and link to it by
<?php echo get_template_directory_uri() . '/tos.php'; ?>
I tried to link the page that way but gives be a blank page.
<?php
/* Template Name: ghfjghjg*/
get_header();
?>
<main id="primary" class="site-main main-header">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</main><!-- #main -->
<?php
get_footer();
Also tried, adding this to my functions.php.
function include_TOS() {
return __DIR__ . 'tos.php';
}
apply_filters( 'template_include', 'include_TOS' );
esc_html_e
is an escaping/localisation function, it's not a way to load and output files. It's unclear what you want to do or why you want to do it, use the edit link underneath the tags to improve and update your question.esc_html_e
, that function does not do what you think it does. Are you trying to create aexample.com/tos
page by putting atos.php
file in your theme?echo
does not include a file, it just prints out a string of text, in this case the location of the file. Also you don't useapply_filters
to add a filter, you useadd_filter
page-tos.php
that would load for a page with the slugtos
. Otherwise you would need to build a rewrite rule and a virtual page which would involves multiple filters, and is not simple to do. I know you want to save yourself a step but you're actually taking something that takes 5 minutes and turning it into 5 hours of work plus more of research