Add a new base file

Hi,
I’m triing to add a file with base.php:
I copied base.php to base-myfile.php

then:

myfile.php >

<?php while (have_posts()) : the_post(); ?>
  <?php get_template_part('templates/page', 'header'); ?>
  <?php get_template_part('templates/content', 'page'); ?>
    my content here
  <?php get_template_part('templates/footer'); ?>
<?php endwhile; ?>

then I create a page in wordpress with the name myfile:

but it didn’t display my content?

Thanks

You need to name the file base-page-myfile.php and have a custom page-myfile.php

Remember the WP hierarchy does not change: https://developer.wordpress.org/themes/basics/template-hierarchy/

page-{slug}.php – If the page slug is recent-news, WordPress will look to use page-recent-news.php.

And here’s the docs on templates: https://roots.io/sage/docs/theme-templates/

The theme wrapper documentation goes into depth about creating new base.php files, but if you’d like to have a customized base.php based off a certain template, just copy it to base-<template name>.php. You can add conditional statements to base.php whenever possible and should generally aim to not have multiple theme wrappers in your theme.

3 Likes

Thanks very usefull.

This topic was automatically closed after 4 hours. New replies are no longer allowed.