I have some pages in Wordpress and I want all of them to have the same basic structure like this: <?php get_header(); ?> <main> <div class="page-wrapper"> <!-- Different page content here --> </div> </main> <?php get_footer(); ?> I tried to do this on a page template: <?php /* Template Name: Test page template */ get_template_part('templates/page'); ?> Test </div> And this on my page template page.php: <?php get_header(); ?> <main class="page-wrapper"> <?php while (have_posts()) : the_post(); the_content(); endwhile; ?> </main> <?php get_footer(); ?> But it just injects the page.php and then puts my "Test" string after the footer. I need the test string to go inside the page-wrapper. How can I have a basic template like this for all my page templates?
Jese Leos
August 19, 2024
Verified user
One way of achiving this would be to use the template_include hook: add_filter('template_include', 'override_template'); function override_template(string $template) { return 'custom-page-template.php'; }