When I set up this site initially, I introduced some changes to the header and footer in their respective php files. Child themes were always an option, but I never used them because I didn’t want to bother with them. There are only a few changes, so I could easily address them when a theme update comes around.
Alas, this is annoying and so I finally created a child theme for twentysixteen. And as it turns out, it wasn’t very hard after all. I just created a folder twentysixteen-child in my WordPress theme folder and added these files:
style.css
/*
Theme Name: Twenty Sixteen Child
Description: Child Theme for jangintel.de
Author: Jan Gintel
Author URI: https://jangintel.de
Template: twentysixteen
Version: 1.0
Text Domain: twenty-sixteen-child
*/
functions.php
<?php
/**
* Child theme stylesheet einbinden in Abhängigkeit vom Original-Stylesheet
*/
function child_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-theme-css', get_stylesheet_directory_uri() .'/style.css' , array('parent-style'));
}
add_action( 'wp_enqueue_scripts', 'child_theme_styles' );?>
Of course I didn’t invent any of this, there’s a section for child themes in the WordPress theme handbook and I also found this Post at holgerfreier.de helpful.
Afterwards, I just needed to add my customised versions of (currently) header.php and footer.php to the child folder, additionally a screenshot.png so it would look nicer in the admin panel.
What I really didn’t want to bother with is learning how to add colours/colour palettes, so I just customised the colour scheme. This is okay since it only needs to be done once.
Background: #616a73, Page background: #4d545c,
Link: #c7c7c7, Both text colours: #f2f2f2
While writing and testing this I discovered that WordPress ignores a template-tags.php
in a child theme. The helpful hint in this file is this:
* Create your own twentysixteen_entry_meta() function to override in a child theme.
So I just modified the functions.php in my child theme to include my originally modified function twentysixteen_entry_meta()
. There might be a more elegant way, but this works for me.
Child theme functions.php
Lines 14-26 are the modifications. They are just commented out to hide the author name in a post.
<?php
/**
* Child theme stylesheet einbinden in Abhängigkeit vom Original-Stylesheet
*/
function child_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-theme-css', get_stylesheet_directory_uri() .'/style.css' , array('parent-style'));
}
function twentysixteen_entry_meta() {
/**
.*This is commented out to prevent the author metadata from showing up in posts.
if ( 'post' === get_post_type() ) {
$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
printf(
'<span class="byline"><span class="author vcard">%1$s<span class="screen-reader-text">%2$s </span> <a class="url fn n" href="%3$s">%4$s</a></span></span>',
get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ),
_x( 'Author', 'Used before post author name.', 'twentysixteen' ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
get_the_author()
);
}
*/
if ( in_array( get_post_type(), array( 'post', 'attachment' ), true ) ) {
twentysixteen_entry_date();
}
$format = get_post_format();
if ( current_theme_supports( 'post-formats', $format ) ) {
printf(
'<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentysixteen' ) ),
esc_url( get_post_format_link( $format ) ),
get_post_format_string( $format )
);
}
if ( 'post' === get_post_type() ) {
twentysixteen_entry_taxonomies();
}
if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
/* translators: %s: Post title. */
comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentysixteen' ), get_the_title() ) );
echo '</span>';
}
}
add_action( 'wp_enqueue_scripts', 'child_theme_styles' );?>
Now I could safely turn on automatic updates for the Twenty Sixteen theme without worrying that this will destroy the look of my site.