Intro to WordPress Child Themes (NERDS Sept 2014)

49
Introduction to Child Themes MEL CHOYCE & KELLY DWAN @MELCHOYCE • @RYELLE NERDSUMMIT • SEPT 2014

Transcript of Intro to WordPress Child Themes (NERDS Sept 2014)

Page 1: Intro to WordPress Child Themes (NERDS Sept 2014)

Introduction to Child Themes

MEL CHOYCE & KELLY DWAN @MELCHOYCE • @RYELLE NERDSUMMIT • SEPT 2014

Page 2: Intro to WordPress Child Themes (NERDS Sept 2014)

Kelly DwanWORDPRESS DEVELOPER

Page 3: Intro to WordPress Child Themes (NERDS Sept 2014)

Mel ChoyceDESIGN ENGINEER AT AUTOMATTIC

Page 4: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 5: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 6: Intro to WordPress Child Themes (NERDS Sept 2014)

setup

Page 7: Intro to WordPress Child Themes (NERDS Sept 2014)

what’s a child theme?

Page 8: Intro to WordPress Child Themes (NERDS Sept 2014)

What is a child theme?

A Child Theme is a theme that overrides and adds elements to another theme (the “Parent” theme) without touching any of the Parent theme’s code. When the parent theme is updated, your changes will be preserved.

Page 9: Intro to WordPress Child Themes (NERDS Sept 2014)

why?

1. If you update your theme, you won’t lose your changes

2. You have greater control over your theme, without having to create one from scratch

3. It’s a great way to learn the basics of WordPress theming

Page 10: Intro to WordPress Child Themes (NERDS Sept 2014)

an example

Page 11: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 12: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 13: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 14: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 15: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 16: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 17: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 18: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 19: Intro to WordPress Child Themes (NERDS Sept 2014)

WordPress themes

Page 20: Intro to WordPress Child Themes (NERDS Sept 2014)

[finder]

Page 21: Intro to WordPress Child Themes (NERDS Sept 2014)

Creating a child theme

Page 22: Intro to WordPress Child Themes (NERDS Sept 2014)

create a new folder in wp-content/themes/

Page 23: Intro to WordPress Child Themes (NERDS Sept 2014)

create style.css

Page 24: Intro to WordPress Child Themes (NERDS Sept 2014)

[editor]

Page 25: Intro to WordPress Child Themes (NERDS Sept 2014)

add a screenshot

Page 26: Intro to WordPress Child Themes (NERDS Sept 2014)

In the WordPress admin, go to Appearance > Themes activate your child theme

Page 27: Intro to WordPress Child Themes (NERDS Sept 2014)

Adding CSS

Page 28: Intro to WordPress Child Themes (NERDS Sept 2014)

[editor]

Page 29: Intro to WordPress Child Themes (NERDS Sept 2014)

Templates

Page 30: Intro to WordPress Child Themes (NERDS Sept 2014)

Basic Theme

• style.css

• index.php

• (screenshot.png)

Page 31: Intro to WordPress Child Themes (NERDS Sept 2014)

Templates

header.php

content

footer.php

index.php

Page 32: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 33: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 34: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 35: Intro to WordPress Child Themes (NERDS Sept 2014)

Overriding a file

• Copy header.php from twentythirteen

• Paste into our child theme

• Open file in text editor

• Copy lines from <div id="navbar" class=“navbar"> to </div><!-- #navbar —>

• Move to above <a class="home-link" …

• Save & view your site

Goal: Move Main Navigation to above the page title a file

Page 36: Intro to WordPress Child Themes (NERDS Sept 2014)

Page Templates

• You can set pages to use different templates if your theme or child theme has other page templates available

no templates available

Page 37: Intro to WordPress Child Themes (NERDS Sept 2014)
Page 38: Intro to WordPress Child Themes (NERDS Sept 2014)

Page with no sidebar• Copy page.php from twentythirteen

• Paste into our child theme *

• Rename to template-no-sidebar.php

• Add Template Name: No Sidebar to the header comment *

• Open in text editor, remove <?php get_sidebar(); ?>

• View a page- if there’s no visible sidebar, add widgets to Secondary Widget Area.

• Edit the page, choose template from the dropdown.

• Update page & view new template.

Page 39: Intro to WordPress Child Themes (NERDS Sept 2014)

Template Hierarchy

http://codex.wordpress.org/images/1/18/Template_Hierarchy.png

Page 40: Intro to WordPress Child Themes (NERDS Sept 2014)

Functionality

Page 41: Intro to WordPress Child Themes (NERDS Sept 2014)

Themes are…

• style.css for appearance

• templates (php files) for layout/HTML/displaying your content

• functions.php for any functionality in your theme

Page 42: Intro to WordPress Child Themes (NERDS Sept 2014)

functions.php• Theme setup function

• Define any navigation menus

• add_theme_support

• post formats, featured images, custom header, custom background, and more

• Set up widget areas

• $content_width

Page 43: Intro to WordPress Child Themes (NERDS Sept 2014)

Featured Imagesadd_theme_support( 'post-thumbnails' );

// width, height, crop mode set_post_thumbnail_size( 604, 270, true );

Regenerate Thumbnails

Page 44: Intro to WordPress Child Themes (NERDS Sept 2014)

More resources

Page 45: Intro to WordPress Child Themes (NERDS Sept 2014)

Next Steps

• http://make.wordpress.org/docs/theme-developer-handbook/Currently in progress, but pretty far along.

• Watch other people!

• Use your browser’s dev tools to see how something’s done

• Check out themes you like, try to read the code

• http://make.wordpress.org/themes/

Page 46: Intro to WordPress Child Themes (NERDS Sept 2014)

NewsTheme Specific

http://themeshaper.com/

General WP News

http://wptavern.com/ http://wordpress.org/news/ http://www.smashingmagazine.com/category/wordpress/ http://www.poststat.us/

Page 47: Intro to WordPress Child Themes (NERDS Sept 2014)

Child ThemeableWP Default themes (also Twenty Eleven, Twenty Twelve)

http://themehybrid.com/themes

http://wordpress.org/themes/responsive

http://wordpress.org/themes/oxygen

http://wordpress.org/themes/vantage

Good Theme developers (to see themes, click Themes):

http://profiles.wordpress.org/automattichttp://profiles.wordpress.org/anlino

Page 48: Intro to WordPress Child Themes (NERDS Sept 2014)

Theme FrameworksThematic

Genesis by StudioPress (paid)

Starter Themes_s

Roots

Bones

Page 49: Intro to WordPress Child Themes (NERDS Sept 2014)

Child Theme Generators

• Plugin: One-Click Child Theme

• WP CLI: wp scaffold child-theme