SlideShare a Scribd company logo
Child Themes
Won’t someone think of the
children?
By Damien Carbery
Photo: https://flic.kr/p/ccHYYL by Justkids
Intro - What's the
problem?
Editing core files is bad.
Editing themes is bad.
Child themes are easy.
Why do you need a child theme?
Perfect … Except
for just one thing
A child theme can help.
Photo: https://flic.kr/p/4bnRok by m.a.r.c.
Let’s create a child theme
Just one file
/*
Name: Child Theme
Template: twentyfifteen
*/
That’s it. Done. Now go Activate it.
What can you do now?
● Change the styles
● Change the layout of posts, pages, archives
or individual ones
● Add new features e.g. add support for
WooCommerce
Changing styles
This is the simplest, least
technical thing that you can
do.
Changing styles Change the page font from
“Noto Serif” to Arial:
body { font-family:
Arial, serif; }
Changing styles
Changing styles
Change the header colours
from #333 to red:
h1, h2, h3, h4, h5,
h6 {
color: #f00;
}
Changing styles
Changing styles
Change ul marker from disc
to a circle:
ul {
list-style: circle;
}
Changing styles
Beyond style changes
Beyond style
changes You can copy a file from the
parent theme and modify it.
Twenty Fifteen displays the
full post content on archive
pages. Let’s change it to
show excerpts.
Excerpts in
Archives
Copy the template file and make your
change.
archive.php displays the
archive.
It uses content.php.
That calls the_content()
so change it to
the_excerpt()
Excerpts in
Archives ....
You have to edit carefully and check
your work.
Now test the change - oops, single pages,
single posts are showing excerpts. The fix:
The code will be:
if (is_archive() ) {
the_excerpt();
}
else {
the_content(
sprintf(
'Continue reading %s',
the_title( false )
) );
}
Adding new
files
Display a specific page or post
differently from all the rest.
You can make use of the template hierarchy to
display a specific page or post differently.
An ‘About page, with a slug of 'about', you can
create a ‘page-about.php’ file in the child
theme.
WooCommerce
Fix or enhance the WooCommerce in
your theme.
If the parent theme doesn’t fully support
WooCommerce, or you want to tweak how it
displays something, you can do this.
Let’s have a look at a quick example...
WooCommerce..
Change that button
Change "Return to shop"
text on empty cart to "Go
buy something already!"
WooCommerce..
Change that button
wp-content/plugins/
woocommerce/
templates/
cart/
cart-empty.php
is copied to
wp-content/themes/
child-theme/
woocommerce/
cart/
cart-empty.php
How does it all work?
Photo: https://flic.kr/p/muJmAv by Christina T.
Find the file
Template directory & stylesheet
directory
First some terms:
● Template directory = parent theme
directory
● Stylesheet directory = child theme
directory
Find the file
Search order
WordPress searches for the
appropriate file in the child theme
directory, then the parent theme
directory.
For a page, slug ‘about’, ID 2 it will
look in:
child-theme/page-about.php
parent-theme/page-about.php
child-theme/page-2.php
parent-theme/page-2.php
child-theme/page.php
parent-theme/page.php
The child theme always wins!
Beyond CSS and page templates
functions.php
Much more control … if you are
comfortable with php.
functions.php is run
automatically after all the
active plugins have been
loaded.
The child theme’s
functions.php runs
directly before the parent
theme’s functions.php.
functions.php...
Override the parent theme
A well written theme, like
Twenty Fifteen, will run its
code at the correct time,
using the appropriate
actions.
You can override these by
changing the priority in
add_action()
functions.php...
Correct the stylesheet loading.
Twenty Fifteen does not
load the stylesheet correctly.
It only loads the child
theme’s spreadsheet.
We can use @import or
redo the loading.
functions.php...
Correct the stylesheet loading… the fix
We run our code after the
parent theme. The code
unloads the child theme
stylesheet and then reloads
it, making the child theme
stylesheet depend on the
parent theme’s file and so
loads after it in the html.
Correct the stylesheet loading...
add_action( 'wp_enqueue_scripts', 'ct_styles', 11 );
function ct_styles() {
wp_dequeue_style( 'twentyfifteen-style' );
wp_enqueue_style( 'twentyfifteen-style',
get_template_directory_uri() .
'/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(),
array('twentyfifteen-style') );
}
Or: http://justintadlock.com/archives/2014/11/03/loading-parent-styles-for-child-themes
What about bad parents
Photo: https://flic.kr/p/7Rdiq6 by IZATRINI.com
Bad parent
themes
Sometimes they do it their way … the
wrong way
Most themes on
wordpress.org get the basics
right but you may find
exceptions. Example:
wp_head();
echo '<link
src="/path/to/".$colour.".css">';
Bad parent
themes
This stylesheet cannot be
overloaded without editing
header.php.
Ideally it should be loaded
via the
‘wp_enqueue_scripts’
action. Report it to the
developer!
Bad parent
themes
Allow child themes to override all files.
A theme may include other
files that a child theme would
like to override e.g. image
files or javascript files.
Example:
wp_enqueue_scripts('cool-stuff',
get_template_directory_uri() . '/js/cool.js',
array( 'jquery' ) );
Bad parent
themes
Use get_theme_file_uri()
Twenty Fifteen hardcodes the
js/html5.js file instead of using this
technique.
We have to wp_dequeue_script()
and wp_enqueue_script() to load
our version. A fix...
wp_enqueue_scripts('cool-stuff',
get_theme_file_uri( '/js/cool.js'
),
array( 'jquery' ) );
Summary - Child themes are great
● Simple to create.
● Changes are not lost when parent theme
updated.
● You can change as much or as little as you
need.
Thanks!
Questions and Corrections to:
Damien Carbery
damien@damiencarbery.com
http://www.damiencarbery.com
@daymobrew
Photo: Mine

More Related Content

PDF
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
Rodolfo Melogli
 
PPTX
WooCommerce: How to Customize WordPress via PHP Snippets
Rodolfo Melogli
 
PDF
Making WooCommerce Your Own
Leo Gopal
 
PDF
Master WooCommerce Troubleshooting
Rodolfo Melogli
 
PDF
Build WordPress themes like a heavyweight - WordCamp Lancaster 2013
Jonny Allbut
 
PPTX
How WPMaintain Improved Page Speed by 16%
WP Engine UK
 
PPTX
Webinar: You Are Too Cheap!
WP Engine
 
PPTX
Pitch Perfect: Agency Secrets to Winning More Business
WP Engine
 
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
Rodolfo Melogli
 
WooCommerce: How to Customize WordPress via PHP Snippets
Rodolfo Melogli
 
Making WooCommerce Your Own
Leo Gopal
 
Master WooCommerce Troubleshooting
Rodolfo Melogli
 
Build WordPress themes like a heavyweight - WordCamp Lancaster 2013
Jonny Allbut
 
How WPMaintain Improved Page Speed by 16%
WP Engine UK
 
Webinar: You Are Too Cheap!
WP Engine
 
Pitch Perfect: Agency Secrets to Winning More Business
WP Engine
 

What's hot (20)

PPTX
WordPress Management & Marketing Tools
WP Engine
 
PPTX
Webinar: On-Page SEO Tips and Tricks
WP Engine
 
PPTX
Webinar: Myths, Mistakes and Management of WooCommerce at Scale
WP Engine
 
PDF
WordCamp Bournemouth 2014 - Designing with data in WordPress
Jonny Allbut
 
PDF
WordCamp Birmingham 2015 - Theme building tricks of the trade
Jonny Allbut
 
PDF
WordCamp Sheffield 2014 Theme Workflow Presentation
Jonny Allbut
 
PDF
Build an App with JavaScript and jQuery - LA - July 27
Thinkful
 
PDF
The Child Theme Dilemma (EN) - Milano Edition
Torsten Landsiedel
 
PPT
Intro to WordPress Child Themes
vegasgeek
 
PPTX
WooCommerce snippets
Rodolfo Melogli
 
PDF
Build an App with JavaScript & jQuery
Aaron Lamphere
 
PDF
How to Sell ANYTHING with WordPress + WooCommerce
Rodolfo Melogli
 
PDF
Child Theme
Shinichi Nishikawa
 
KEY
Word press 3 @ wordcamp
Tris Hussey
 
PDF
10 PHP Snippets to Increase WooCommerce Sales
Rodolfo Melogli
 
PDF
Teaching Your Clients How to Use WordPress
Nile Flores
 
KEY
Wp and jq
Digitally
 
PPTX
Professional WordPress Workflow - WPDay 2015
Maurizio Pelizzone
 
KEY
5 Tips for Writing Better JavaScript
Nael El Shawwa
 
PPT
How to use to build a website using WordPress: For normal people
Tris Hussey
 
WordPress Management & Marketing Tools
WP Engine
 
Webinar: On-Page SEO Tips and Tricks
WP Engine
 
Webinar: Myths, Mistakes and Management of WooCommerce at Scale
WP Engine
 
WordCamp Bournemouth 2014 - Designing with data in WordPress
Jonny Allbut
 
WordCamp Birmingham 2015 - Theme building tricks of the trade
Jonny Allbut
 
WordCamp Sheffield 2014 Theme Workflow Presentation
Jonny Allbut
 
Build an App with JavaScript and jQuery - LA - July 27
Thinkful
 
The Child Theme Dilemma (EN) - Milano Edition
Torsten Landsiedel
 
Intro to WordPress Child Themes
vegasgeek
 
WooCommerce snippets
Rodolfo Melogli
 
Build an App with JavaScript & jQuery
Aaron Lamphere
 
How to Sell ANYTHING with WordPress + WooCommerce
Rodolfo Melogli
 
Child Theme
Shinichi Nishikawa
 
Word press 3 @ wordcamp
Tris Hussey
 
10 PHP Snippets to Increase WooCommerce Sales
Rodolfo Melogli
 
Teaching Your Clients How to Use WordPress
Nile Flores
 
Wp and jq
Digitally
 
Professional WordPress Workflow - WPDay 2015
Maurizio Pelizzone
 
5 Tips for Writing Better JavaScript
Nael El Shawwa
 
How to use to build a website using WordPress: For normal people
Tris Hussey
 
Ad

Similar to Child Themes - WordCamp Dublin 2017 (20)

PDF
Child Themes (WordCamp Dublin 2017) with notes
Damien Carbery
 
PPT
Child Themes in WordPress
Jeff Cohan
 
PPTX
WordPress HTML, CSS & Child Themes
Michelle Ames
 
PPT
WordPress Child Themes
rfair404
 
PPTX
Customizing WordPress Themes
Laura Hartwig
 
PDF
The Child Theme Dilemma (EN)
Torsten Landsiedel
 
PPT
Week 9 - Introduction to Child Themes
henri_makembe
 
PDF
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
LinnAlexandra
 
KEY
WordPress Child Themes
openchamp
 
ODP
Meetup child-themes
DaisyOlsen
 
ODP
Meetup child-themes
DaisyOlsen
 
PPTX
The Way to Theme Enlightenment
Amanda Giles
 
PDF
Intro to WordPress Child Themes (NERDS Sept 2014)
Kelly Dwan
 
ODP
Meetup child-themes
DaisyOlsen
 
PPTX
WordPress Child Themes: The what. The why. The how.
Janelle Reichman
 
PPTX
Introduction to WordPress Child Theming, WordCamp Kansas City, 2015
topher1kenobe
 
PPTX
Responsive Theme Workshop - WordCamp Columbus 2015
Joe Querin
 
ODP
Best practices in WordPress Development
Mindfire Solutions
 
PDF
wp-n00b.php
Temian Vlad
 
ZIP
Theme Kickstart
Peter
 
Child Themes (WordCamp Dublin 2017) with notes
Damien Carbery
 
Child Themes in WordPress
Jeff Cohan
 
WordPress HTML, CSS & Child Themes
Michelle Ames
 
WordPress Child Themes
rfair404
 
Customizing WordPress Themes
Laura Hartwig
 
The Child Theme Dilemma (EN)
Torsten Landsiedel
 
Week 9 - Introduction to Child Themes
henri_makembe
 
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
LinnAlexandra
 
WordPress Child Themes
openchamp
 
Meetup child-themes
DaisyOlsen
 
Meetup child-themes
DaisyOlsen
 
The Way to Theme Enlightenment
Amanda Giles
 
Intro to WordPress Child Themes (NERDS Sept 2014)
Kelly Dwan
 
Meetup child-themes
DaisyOlsen
 
WordPress Child Themes: The what. The why. The how.
Janelle Reichman
 
Introduction to WordPress Child Theming, WordCamp Kansas City, 2015
topher1kenobe
 
Responsive Theme Workshop - WordCamp Columbus 2015
Joe Querin
 
Best practices in WordPress Development
Mindfire Solutions
 
wp-n00b.php
Temian Vlad
 
Theme Kickstart
Peter
 
Ad

Recently uploaded (20)

PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Exploring AI Agents in Process Industries
amoreira6
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Activate_Methodology_Summary presentatio
annapureddyn
 
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Presentation about variables and constant.pptx
kr2589474
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 

Child Themes - WordCamp Dublin 2017

  • 1. Child Themes Won’t someone think of the children? By Damien Carbery Photo: https://flic.kr/p/ccHYYL by Justkids
  • 2. Intro - What's the problem? Editing core files is bad. Editing themes is bad. Child themes are easy.
  • 3. Why do you need a child theme?
  • 4. Perfect … Except for just one thing A child theme can help. Photo: https://flic.kr/p/4bnRok by m.a.r.c.
  • 5. Let’s create a child theme
  • 6. Just one file /* Name: Child Theme Template: twentyfifteen */ That’s it. Done. Now go Activate it.
  • 7. What can you do now? ● Change the styles ● Change the layout of posts, pages, archives or individual ones ● Add new features e.g. add support for WooCommerce
  • 8. Changing styles This is the simplest, least technical thing that you can do.
  • 9. Changing styles Change the page font from “Noto Serif” to Arial: body { font-family: Arial, serif; }
  • 11. Changing styles Change the header colours from #333 to red: h1, h2, h3, h4, h5, h6 { color: #f00; }
  • 13. Changing styles Change ul marker from disc to a circle: ul { list-style: circle; }
  • 16. Beyond style changes You can copy a file from the parent theme and modify it. Twenty Fifteen displays the full post content on archive pages. Let’s change it to show excerpts.
  • 17. Excerpts in Archives Copy the template file and make your change. archive.php displays the archive. It uses content.php. That calls the_content() so change it to the_excerpt()
  • 18. Excerpts in Archives .... You have to edit carefully and check your work. Now test the change - oops, single pages, single posts are showing excerpts. The fix: The code will be: if (is_archive() ) { the_excerpt(); } else { the_content( sprintf( 'Continue reading %s', the_title( false ) ) ); }
  • 19. Adding new files Display a specific page or post differently from all the rest. You can make use of the template hierarchy to display a specific page or post differently. An ‘About page, with a slug of 'about', you can create a ‘page-about.php’ file in the child theme.
  • 20. WooCommerce Fix or enhance the WooCommerce in your theme. If the parent theme doesn’t fully support WooCommerce, or you want to tweak how it displays something, you can do this. Let’s have a look at a quick example...
  • 21. WooCommerce.. Change that button Change "Return to shop" text on empty cart to "Go buy something already!"
  • 22. WooCommerce.. Change that button wp-content/plugins/ woocommerce/ templates/ cart/ cart-empty.php is copied to wp-content/themes/ child-theme/ woocommerce/ cart/ cart-empty.php
  • 23. How does it all work? Photo: https://flic.kr/p/muJmAv by Christina T.
  • 24. Find the file Template directory & stylesheet directory First some terms: ● Template directory = parent theme directory ● Stylesheet directory = child theme directory
  • 25. Find the file Search order WordPress searches for the appropriate file in the child theme directory, then the parent theme directory. For a page, slug ‘about’, ID 2 it will look in: child-theme/page-about.php parent-theme/page-about.php child-theme/page-2.php parent-theme/page-2.php child-theme/page.php parent-theme/page.php The child theme always wins!
  • 26. Beyond CSS and page templates
  • 27. functions.php Much more control … if you are comfortable with php. functions.php is run automatically after all the active plugins have been loaded. The child theme’s functions.php runs directly before the parent theme’s functions.php.
  • 28. functions.php... Override the parent theme A well written theme, like Twenty Fifteen, will run its code at the correct time, using the appropriate actions. You can override these by changing the priority in add_action()
  • 29. functions.php... Correct the stylesheet loading. Twenty Fifteen does not load the stylesheet correctly. It only loads the child theme’s spreadsheet. We can use @import or redo the loading.
  • 30. functions.php... Correct the stylesheet loading… the fix We run our code after the parent theme. The code unloads the child theme stylesheet and then reloads it, making the child theme stylesheet depend on the parent theme’s file and so loads after it in the html.
  • 31. Correct the stylesheet loading... add_action( 'wp_enqueue_scripts', 'ct_styles', 11 ); function ct_styles() { wp_dequeue_style( 'twentyfifteen-style' ); wp_enqueue_style( 'twentyfifteen-style', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('twentyfifteen-style') ); } Or: http://justintadlock.com/archives/2014/11/03/loading-parent-styles-for-child-themes
  • 32. What about bad parents Photo: https://flic.kr/p/7Rdiq6 by IZATRINI.com
  • 33. Bad parent themes Sometimes they do it their way … the wrong way Most themes on wordpress.org get the basics right but you may find exceptions. Example: wp_head(); echo '<link src="/path/to/".$colour.".css">';
  • 34. Bad parent themes This stylesheet cannot be overloaded without editing header.php. Ideally it should be loaded via the ‘wp_enqueue_scripts’ action. Report it to the developer!
  • 35. Bad parent themes Allow child themes to override all files. A theme may include other files that a child theme would like to override e.g. image files or javascript files. Example: wp_enqueue_scripts('cool-stuff', get_template_directory_uri() . '/js/cool.js', array( 'jquery' ) );
  • 36. Bad parent themes Use get_theme_file_uri() Twenty Fifteen hardcodes the js/html5.js file instead of using this technique. We have to wp_dequeue_script() and wp_enqueue_script() to load our version. A fix... wp_enqueue_scripts('cool-stuff', get_theme_file_uri( '/js/cool.js' ), array( 'jquery' ) );
  • 37. Summary - Child themes are great ● Simple to create. ● Changes are not lost when parent theme updated. ● You can change as much or as little as you need.
  • 38. Thanks! Questions and Corrections to: Damien Carbery [email protected] http://www.damiencarbery.com @daymobrew Photo: Mine