WordPress templates are pretty good, they make it easy to get a website up and running easily and quickly. The disadvantage is that if you want to edit them in depth then you have to spend a lot of time figuring out what you need to change and then how to change it (confusing docs, inexperienced advice, etc ). Even if you do you can lose that change in the next update. To combat this I wrote this guide, which will show you how to modify a wordpress templates correctly. When modifying a theme the best way to do it is to build a child theme. These are themes that rely on the files in the main theme.
Step 1: Create a child wordpress templates directory.
To create a child wordpress directory log into cpanel or the ssh into the hosting server. The theme I have used for my blog is minimalistblogger. I created a directory called minamilistblogger-child.
sudo su
mkdir minimalistblogger-child
Run as root because you most likely don’t have the permissions to create this directory and then make the directory.
Step 2: Create functions.php and style.css files
Create a functions.php and style.css files, these are required for the child theme to work.
cd minimalistblogger-child
touch functions.php
touch style.css
Step 3: Edit both functions.php and styles.css
Copy the following into functions.php. This is the real link between the the child and main theme.
nano functions.php
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
In the style.css you will need to add in the the template field in the comments section. Just copy the text below and change the references to minimalistblogger to the theme that you are using.
/*
Theme Name: MinimalistBlogger-child
Theme URI: https://vishnu.unnikrishnan.com.au
Author: Vishnu Unnikrishnan
Author URI: https://vishnu.unnikrishnan.com.au
Description: MinimalistBlogger is a responsive WordPress blog and news theme made for bloggers and newspapers....
Version: 1.7
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
Text Domain: minimalistblogger
Tags: blog, news, right-sidebar, post-formats, custom-background, custom-logo, custom-menu, featured-images, threaded-comments, sticky-post, translation-ready, two-columns, custom-header, footer-widgets, theme-options, entertainment
*******************************
Template:minimalistblogger
Text Domain: minimalistblogger
********************************
This theme, like WordPress, is licensed under the GPL v2 or later.
Use it to make something cool, have fun, and share what you've learned with others.
*/
These steps will allow you to modify wordpress templates without having to worry about the changes. In the next instalment I will show you how to create your own page template to make a page of posts look pretty.