Modifying the Twenty Sixteen Theme


(Grant Smith) #1

Hi,

I’m having to rebuild a inherted site due to the amount of issues the original site has. I decided to modify the Twenty Sixteen theme as the original site isn’t complicated and I thought this may make theme development a little quicker.

Each page title sits in a full width block above the content area. Here is an example: http://acornantics.co.uk/

I figured this would just be a case of editing the index.php file by moving the following code to above the content area. For example:

Original code in index.php

get_header(); ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">

		<?php if ( have_posts() ) : ?>

			<?php if ( is_home() && ! is_front_page() ) : ?>
				<header>
					<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
				</header>
			<?php endif; ?>

And changing this to:

get_header(); ?>

	<?php if ( have_posts() ) : ?>

		<?php if ( is_home() && ! is_front_page() ) : ?>
			<header>
				<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
			</header>
	<?php endif; ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">

This seems to have no effect though?

Some help would be appreaciated.

Thanks in advanced


(Leland Fiegel) #2

A few things:

  1. In a theme that contains files like single.php, page.php, index.php, archive.php, search.php, 404.php …the index.php file only affects the blog homepage.

You need to edit single.php for single posts, and page.php for pages.

Read up on the Template Hierarchy for more information.

  1. Although not entirely relevant considering the above point, the if ( is_home() && ! is_front_page() ) conditional tag will only have an effect on a blog homepage that is not the front page. The exclamation point before is_front_page() means “not.”

For example, if the blog was displayed on example.com/blog/ instead of the front page. This would be set on the Reading Settings page.

So if your blog homepage was set to display on the front page (which is the WordPress default), that’s why you didn’t notice any difference even on the blog homepage.

Read up on Conditional Tags for more info.

  1. I haven’t looked into this particular situation, but in general…before I resort to modifying markup, I always make sure there’s not a practical CSS-only way of handling things first.

(Rhys Wynne) #3

As an aside, I’d recommend using a child theme (if not already). If you update the theme you could lose your changes.