Child Themes in WordPress

Post on 08-May-2015

1,651 views 0 download

description

For WordCamp ATL 2012

transcript

slideshare.net/jdcohan

Child Themes

Get Started On The Right Foot With Creating

Jeff Cohan, nSiteful Web Builders

WordCamp Atlanta 2012

@jdcohan

jeff@nsiteful.com

slideshare.net/jdcohan

Survey

• By a show of hands, who...– has given presentations on child themes?– has created and used child themes?– understands child themes enough to explain

what they are?

slideshare.net/jdcohan

What is a WordPress Theme?

• A collection of files that work together to determine the look and presentation (and functionality) of a WordPress site.

• Consists of:– style sheet(s)– template file(s)– images– code files (functions)

slideshare.net/jdcohan

What is a Child Theme?

• Official Definition:– A WordPress child theme is a theme that

inherits the functionality of another theme, called the parent theme, and allows you to modify, or add to, the functionality of that parent theme.

• Inherit = either or both of:– supplement– override

slideshare.net/jdcohan

WHY Use Child Themes?

• Security:– Avoid screwing up a perfectly good theme,

crashing site

• Maintainability:– Preserves your modifications when parent

theme is updated

• Self-Education:– Helps you learn WordPress' innards (clone

and go)

slideshare.net/jdcohan

WHEN to Use Child Themes:

• As soon as you want to modify the site's look, presentation, or functionality

• I.e., ALWAYS!

• Examples:– change color scheme– change "read more"– match blog to non-WP site– change footer contents*

slideshare.net/jdcohan

How?

• Create a directory under/wp-content/themes/– as sibling directory of parent (yeah:

counterintuitive)

• Upload a properly-formatted (?) stylesheet.

• Voila. Honest. Voila.

slideshare.net/jdcohan

Child Theme Components

• Required:– Style Sheet: style.css (S and/or O)

• Optional:– Template files (O)– functions.php (S)– other files (images, JavaScript, php includes)

• REALLY optional:– screenshot.png (300x225)

slideshare.net/jdcohan

Style Sheet (style.css) Format

• Required Commented Information Block (at top)– Required elements:

• Theme Name• Template (parent theme name)

– Optional elements:• Theme URI, Description, Author URI, Author,

Version

• @import directives (optional)

slideshare.net/jdcohan

Sample Child Style Sheet

slideshare.net/jdcohan

Pecking Order Quick Review

• style.css: supplements and/or overrides– The Cascade: weight, origin, specificity, order

• Template Files: override– understand Template Hierarchy

• functions.php: supplements - overridable!– child loads first– use function names NOT used by parent

theme*

slideshare.net/jdcohan

Mods Through CSS

• Options:– Override any rule from parent*

• *beware of specificity

– Add rule(s) for new components

• Let's change that footer with CSS:#footer { background: url(images/cclogos.png)

no-repeat right center transparent;}

slideshare.net/jdcohan

Mods Through Templates

• Building Blocks:– Template Tags– Function Reference– Template Hierarchy

slideshare.net/jdcohan

WordPress Template Hierarchy

slideshare.net/jdcohan

Mods Through Templates

• Options:– replace parent template

• e.g., customized home.php

– add specific template lacking in parent• e.g., tag.php instead of archives.php

– add custom template• e.g., custom php code

• Let's change that footer with template...

slideshare.net/jdcohan

Mods Through Functions

• Building Blocks:– Function Reference– Hooks (Actions & Filters)

• Examples:– favicon link– change the "read more" text– complex scripts

slideshare.net/jdcohan

Favicon via Function

slideshare.net/jdcohan

Read More via Function

slideshare.net/jdcohan

All of the Above

• Custom Template, Custom Scripts, Custom CSS

slideshare.net/jdcohan

Add Blog to Existing Site

• client might love existing site

• client might not have the budget to redo site in WordPress

• client just wants a blog that integrates seamlessly

slideshare.net/jdcohan

Eaton Academy Main Site

slideshare.net/jdcohan

Eaton Academy Blog

slideshare.net/jdcohan

Lessons In Your Home Main Site

slideshare.net/jdcohan

Lessons In Your Home Blog

slideshare.net/jdcohan

Starkers!

• The completely naked theme for WordPress

• Free of all style, presentational elements, and non-semantic markup, Starkers is the perfect ‘blank slate’ for your projects, as it’s a stripped-back version of the ‘Twenty Ten’ theme that ships with WordPress.

• http://starkerstheme.com/

slideshare.net/jdcohan

Why Starkers?

• What's Removed:– non-semantic presentational class names

(class="alignleft")– non-semantic HTML elements (<hr />, <br />– unnecessary elements (<div class="entry">)

• What's Kept:– IDs to preserve functionality

(<h3 id="respond">)

slideshare.net/jdcohan

Wait for it...

slideshare.net/jdcohan

Resources

slideshare.net/jdcohan

WordPress Function Reference

slideshare.net/jdcohan

WordPress Template Tags

slideshare.net/jdcohan

PHP.NET

slideshare.net/jdcohan

PHPXref of WP Trunk (Yoast)

slideshare.net/jdcohan

WordPress Answers - Stack Exchange

slideshare.net/jdcohan

LinkedIn WordPress Group

slideshare.net/jdcohan

Color Scheme Designer

slideshare.net/jdcohan

Digging Into WordPress

slideshare.net/jdcohan

CSS: The Definitive Guide 3rd Edition

slideshare.net/jdcohan

TopStyle

slideshare.net/jdcohan

Firebug