So I’m delving deeper into WordPress and enjoying discovering just how powerful and flexible the tools are at your disposal when building web pages and posts. I was a little fearful in my earlier WordPress post as to how restrictive your powers will be to really customise the look of your site.
Well I’ve spent today brushing up on child themes within WordPress and many of my fears have been allayed. It’s all become a little clearer to me now. Creating a child theme ensures you can make the CSS tweaks to the site as you wish, without amending the parent theme CSS. It means updates to the parent theme can be made without any possibility of breaking your site. Once you set up the child theme, it does speed up the development time and using child themes will help my education in all things WordPress.
What is revealing is that the old way of importing the parent theme stylesheet using the @import method is no longer termed as ‘best practice’ on the codex site. You still enter in the necessary text in the child theme CSS file:
/*
Theme Name: Twenty Sixteen Child
Theme URI: http://example.com/twenty-sixteen-child/
Description: Twenty Sixteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentysixteen
Version: 1.0.0
*/
Instead of inserting the @import method to link to the CSS of the parent theme, you need to create a child theme version of the function.php file and include the text below:
<?php
add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
function theme_enqueue_styles() {
wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );
}
?>
This ensures the child theme’s stylesheet will usually be loaded automatically. You can then happily start tweaking the layout of your site, safe in the knowledge that the site layout is robust and unlikely to breakdown.
I’m starting to feel ever more confident now about using WordPress. I’m starting to trust the tools now and once you have that confidence, you feel you’re winning the battle to really master the skills required.