Top Banner
BIRTHING A CHILD THEME BIRTHING A CHILD THEME Presented by / Lauren Pittenger @laurenpittenger Slides: Download Child Theme: http://bit.ly/birthing-child-themes github.com/lepittenger/twentyfifteen-child
41

Birthing a Child Theme - WordCamp Scranton

Apr 15, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Birthing a Child Theme - WordCamp Scranton

BIRTHING A CHILD THEMEBIRTHING A CHILD THEMEPresented by / Lauren Pittenger @laurenpittenger

Slides:

Download Child Theme:

http://bit.ly/birthing-child-themes

github.com/lepittenger/twentyfifteen-child

Page 2: Birthing a Child Theme - WordCamp Scranton

Front End Designer & Developer at LBDesign, a globalcommunications consultancyInstructor for the Women's Coding Collective ofWordPress Basics and JavaScript & jQuery coursesTA & Volunteer for GirlDevelopIt

ABOUT LAURENABOUT LAUREN

Page 3: Birthing a Child Theme - WordCamp Scranton

You manage a WordPress siteYou have a blog that's powered by WordPressthat uses a default themeYou want to learn more about WordPresstheme developmentYou want to get your feet wet in PHP and CSSYou want to be able to customize your website

ABOUT YOUABOUT YOU

Page 4: Birthing a Child Theme - WordCamp Scranton

What is a child theme?Why use a child theme?How to create a child themeThree examples of what we cando with a child theme

WHAT WE'LL COVERWHAT WE'LL COVER

Page 5: Birthing a Child Theme - WordCamp Scranton

LET'S GO!LET'S GO!

Page 6: Birthing a Child Theme - WordCamp Scranton

A Child Theme is a theme that inherits the styles andfunctionality of another theme, but lets us override and add

our own elements without touching any of the ParentTheme's code

WHAT IS A CHILD THEME?WHAT IS A CHILD THEME?

Page 7: Birthing a Child Theme - WordCamp Scranton
Page 8: Birthing a Child Theme - WordCamp Scranton

WHY USE A CHILD THEME?WHY USE A CHILD THEME?

Page 9: Birthing a Child Theme - WordCamp Scranton

#1 RULE#1 RULENEVER MODIFY WORDPRESS THEME (OR CORE) FILESNEVER MODIFY WORDPRESS THEME (OR CORE) FILES

Page 10: Birthing a Child Theme - WordCamp Scranton

CHILD THEMES PREVENT USCHILD THEMES PREVENT USFROM LOSING OUR CHANGESFROM LOSING OUR CHANGES

Page 11: Birthing a Child Theme - WordCamp Scranton

CREATING A CHILD THEMECREATING A CHILD THEME1. Child theme folder2. style.css3. functions.php

Page 12: Birthing a Child Theme - WordCamp Scranton

CHILD THEME DIRECTORYCHILD THEME DIRECTORYwp-content/themes/my-child-theme

Page 13: Birthing a Child Theme - WordCamp Scranton

TWO NECESSARY FILESTWO NECESSARY FILES

Page 14: Birthing a Child Theme - WordCamp Scranton

STYLE.CSSSTYLE.CSS/* Theme Name: Twenty Fifteen Child Theme Theme URI: http://themeuri.com/twenty-fifteen-child/ Description: Twenty Fifteen Child Theme Author: Lauren Pittenger Author URI: http://laurenpittenger.com Template: twentyfifteen Version: 1.0.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready Text Domain: twenty-fifteen-child*/

Page 15: Birthing a Child Theme - WordCamp Scranton

STYLE.CSSSTYLE.CSS

/* Theme Name: Twenty Fifteen Child Theme Template: twentyfifteen*/

Page 16: Birthing a Child Theme - WordCamp Scranton

FUNCTIONS.PHPFUNCTIONS.PHPfunction child_theme_enqueue_styles() {

wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}

add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );

Page 17: Birthing a Child Theme - WordCamp Scranton

NOW WE CAN ACTIVATE OUR BABY!NOW WE CAN ACTIVATE OUR BABY!

Page 18: Birthing a Child Theme - WordCamp Scranton
Page 19: Birthing a Child Theme - WordCamp Scranton

SCREENSHOT.PNGSCREENSHOT.PNG 880×660

Page 20: Birthing a Child Theme - WordCamp Scranton

AT THIS POINT,AT THIS POINT,CHILD THEME LOOKS & BEHAVESCHILD THEME LOOKS & BEHAVES

EXACTLY AS PARENT THEMEEXACTLY AS PARENT THEME

Page 21: Birthing a Child Theme - WordCamp Scranton
Page 22: Birthing a Child Theme - WordCamp Scranton

NOW WHAT?NOW WHAT?1. CSS changes2. Template changes3. functions.php changes

Page 23: Birthing a Child Theme - WordCamp Scranton

BASIC STYLE CHANGESBASIC STYLE CHANGES.page-header { border-left-color: orange;}

.entry-footer { background: url('images/bg.png') repeat; color: white;}.entry-footer a { color: white;}

#sidebar { background: #772322; color: white;}.widget-title, #sidebar a { color: white;}

Page 24: Birthing a Child Theme - WordCamp Scranton
Page 25: Birthing a Child Theme - WordCamp Scranton

!IMPORTANT!IMPORTANT.page-header { border-left-color: orange !important;}

Page 26: Birthing a Child Theme - WordCamp Scranton

LITTLE BIT FANCIER STYLE CHANGESLITTLE BIT FANCIER STYLE CHANGES

* { font-family: 'Andika', sans-serif;}

.entry-title,

.widget-title,

.site-title { font-family: 'Underdog', serif;}

style.css

functions.php

function child_theme_enqueue_styles() {

wp_enqueue_style( 'google-fonts', 'http://fonts.googleapis.com/css?family=Andika|Underdog'); wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );

Page 27: Birthing a Child Theme - WordCamp Scranton
Page 28: Birthing a Child Theme - WordCamp Scranton

FUNCTIONS.PHP CHANGESFUNCTIONS.PHP CHANGES

Page 29: Birthing a Child Theme - WordCamp Scranton
Page 30: Birthing a Child Theme - WordCamp Scranton
Page 31: Birthing a Child Theme - WordCamp Scranton
Page 32: Birthing a Child Theme - WordCamp Scranton
Page 33: Birthing a Child Theme - WordCamp Scranton
Page 34: Birthing a Child Theme - WordCamp Scranton
Page 35: Birthing a Child Theme - WordCamp Scranton

TEMPLATE CHANGESTEMPLATE CHANGES

Page 36: Birthing a Child Theme - WordCamp Scranton

TEMPLATE CHANGESTEMPLATE CHANGES1. Figure out where you want your change2. Find the appropriate parent theme

template (header.php)3. Copy template into child theme,

preserving its file name4. Edit away!

Page 37: Birthing a Child Theme - WordCamp Scranton

ADDING BANNER IMAGEADDING BANNER IMAGE<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/header.jpg">

header.php

Page 38: Birthing a Child Theme - WordCamp Scranton

ADDING OUR OWN TEMPLATESADDING OUR OWN TEMPLATESWe can leverage the WordPress template hierarchy to our

advantage if our parent theme doesn't provide us with atemplate that we need

Page 39: Birthing a Child Theme - WordCamp Scranton

LOCATING THEME DIRECTORIESLOCATING THEME DIRECTORIESThe Parent Theme Directory

The Child Theme Directory

get_stylesheet_directory()

get_stylesheet_directory_uri()

get_template_directory()

get_template_directory_uri()

Page 40: Birthing a Child Theme - WordCamp Scranton

PARENT THEME SELECTIONPARENT THEME SELECTIONWhen selecting a parent theme,consider your needs carefullyRemember that if you need to makea lot of major changes, perhaps anothersolution would be better suited

Page 41: Birthing a Child Theme - WordCamp Scranton

ANY QUESTIONS?ANY QUESTIONS?Slides:

Demo Child Theme:

Note: demo theme depends on twentyfifteen theme

bit.ly/birthing-child-themes

github.com/lepittenger/twentyfifteen-child

@laurenpittenger

laurenpittenger.com