Create alternative page templates in Underscores theme

Create a template with no title

I look to create templates with no automatic title so that I can use a good title for SEO and manually insert my own h1 header in the body of the page.

To do this, make a copy of the file template-parts/content-page.php and call it content-no-title.php

In your new file, content-no-title.php, remove the following lines

	<header class="entry-header">
		<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
	</header><!-- .entry-header -->

Next, make a file of page.php and call it notitle.php

In your new file, notitle.php, replace the first few lines

<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package {theme_slug}
 */

with

<?php
/*
 * Template Name: No Title
 * @package {theme_slug}
 */

You will also need to replace

get_template_part( 'template-parts/content', 'page' );

with

get_template_part( 'template-parts/content', 'no-title' );

To create a full width template

Create a new file called fullwidth.php and copy the following code.

<?php
/*
 * Template Name: Full Width
 * @package {theme_slug}
 */

get_header(); ?>
<div class="container">
	<div id="primary" class="content-area">
		<main id="main" class="site-main">

			<?php
			while ( have_posts() ) : the_post();

				get_template_part( 'template-parts/content', 'page' );

				// If comments are open or we have at least one comment, load up the comment template.
				if ( comments_open() || get_comments_number() ) :
					comments_template();
				endif;

			endwhile; // End of the loop.
			?>

		</main><!-- #main -->
	</div><!-- #primary -->
</div><!-- .container -->
<?php
get_footer();

Leave a Reply