SlideShare une entreprise Scribd logo
1  sur  47
The Way to
Theme Enlightenment
Amanda Giles
@AmandaGilesNH
https://amandagiles.com/enlightenment
Who am I?
• Programming since 1985 (Basic & Logo!)
• Made my first website in 1994
• Professionally coding for 20 years
• Independent Consultant since 2006
• Working with WordPress since 2009
• Started the Seacoast NH WordPress
Meetup in 2011
• Co-Created Spark Development
WordPress Development Agency in 2016
Beginning WordPress Development
http://www.usgamesinc.com/tarotblog/
Beginning WordPress Development
http://www.soulgeniusbranding.com/blog/2015/10/19/trading-in-my-know-it-all-for-a-beginners-mind
Child Themes
If you’re editing an existing theme…
CREATE A CHILD THEME!
• A child theme separates your customizations
from the existing theme
• Existing theme becomes the “parent” theme
• Both themes are installed on your site
• Child themes allows for upgrades of the parent
theme (without losing customizations!)
• WordPress looks to the child theme first for
files it needs. If not found, it then looks in the
parent theme folder.
https://developer.wordpress.org/themes/advanced-topics/child-themes/
Child Themes
1. Make a child theme by adding a new folder
under wp-content/themes
2. Create style.css with informational header:
/*
Theme Name: My Child Theme
Description: Child theme for John’s company
Theme Author: Jane Doe
Author URI: http://janedoes.com
Template: twentyseventeen
*/
Child Themes
3. Create functions.php and include parent theme’s
CSS file:
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_css' );
function mytheme_enqueue_css() {
//Include parent theme style
wp_enqueue_style( 'parent-style',
get_template_directory_uri() . '/style.css' );
//Include child theme style (dependent on parent style)
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( 'parent-style' ) );
}
Template Hierarchy
How WordPress determines which template file
(in your theme) to use to display a particular
page on your website.
Called a “hierarchy” because WordPress looks in
a specific order (from most specific to least
specific) to determine which file to use.
Important to understand so you don’t repeat
yourself unnecessarily in theme files.
Your entire theme could consist of just 2 files:
style.css + index.php
But that’s not usually the case!
Template Hierarchy
https://developer.wordpress.org/themes/basics/template-hierarchy/
https://wphierarchy.com/
Template Hierarchy Example
1. category-$slug.php Variable Template
2. category-$id.php Variable Template
3. category.php Secondary Template
4. archive.php Primary Template
5. index.php Primary Template
Useful Theme Functions
get_header ( string $name = null )
get_sidebar (string $name = null )
get_footer (string $name = null )
get_template_part ( string $slug, string $name = null )
get_bloginfo ( string $show = '', string $filter = 'raw' )
Conditional Tags
Examples include:
• is_front_page()
• is_admin()
• is_single() / is_singular()
• is_page() / is_page(43) / is_page(‘about’)
• Is_page_template()
• is_category() / is_category(7) / is_category(‘news’)
• is_post_type_archive()
• Is_tax()
https://developer.wordpress.org/themes/basics/conditional-tags/
Content Functions
Examples include:
the_title() get_the_title()
the_permalink() get_the_permalink()
the_date() get_the_date()
the_post_thumbnail() get_the_post_thumbnail()
the_excerpt() get_the_excerpt()
the_content() get_the_content()
$content = apply_filters('the_content', get_the_content());
Functions.php
If you have a functions.php file in your active theme
directory, WordPress will automatically load this file
when viewing both the front and back-end of your
website.
Within this file, you can write your own functions and
call WordPress core or plugin functions.
Function names should be unique to avoid conflicts.
https://codex.wordpress.org/Functions_File_Explained
CSS Classes – body_class()
Most WordPress themes use body_class() on the
body tag and this gives you a very helpful set of CSS
classes.
<body <?php body_class(); ?>>
<body class="page page-id-89 page-template-default">
<body class="archive category category-news category-1
logged-in admin-bar no-customize-support">
<body class="single single-post postid-247 single-
format-standard">
<body class="single single-event postid-3448">
CSS Classes – post_class()
Many WordPress themes use post_class() on the post
<article> tag (single and archive pages) and this gives
you a very helpful set of CSS classes.
<article id="post-<?php the_ID(); ?>" <?php
post_class(); ?>>
<article id="post-247" class="post-247 post type-post
status-publish format-standard hentry category-news">
<article id="post-7537" class="post-7537 featured-
stories type-featured-stories status-publish hentry" >
The Loop & WP_Query()
“The Loop” is at the heart of all WordPress pages.
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();
get_template_part(
'template-parts/content',
get_post_type()
);
endwhile; // End the loop.
endif;
The Loop & WP_Query()
Use WP_Query() to write your own queries to pull
content from your WordPress site.
Define an array of your query parameters to pass to
WP_Query():
<?php
//Get 20 Books in alphabetical order by title
$args = array(
'post_type' => 'book',
'post_per_page' => 20,
'orderby' => 'title',
'order' => 'ASC'
);
The Loop & WP_Query()
Then pass that array of query arguments to WP_Query():
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) :
$query->the_post();
get_template_part(
'template-parts/content', 'book' );
endwhile;
endif;
//Restore the $post global to the current post in
// the main query – VERY IMPORTANT!
wp_reset_postdata();
The Loop & WP_Query()
Make complex queries using tax_query:
$args = array(
'post_type' => 'book',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'genre',
'field' => 'slug',
'operator' => 'IN',
'terms' => 'romance'
array(
'taxonomy' => 'genre',
'field' => 'slug',
'terms' => 'featured'
) );
https://developer.wordpress.org/reference/classes/wp_query/
The Loop & WP_Query()
Make complex queries using meta_query:
$args = array(
'post_type' => 'book',
'meta_query' => array(
'relation' => ‘OR',
array(
'key' => 'rating',
'value' => '3',
'compare' => '>=',
'type' => 'numeric',
array(
'key' => 'recommended',
'value' => 'Y',
'compare' => '=',
)
);
https://developer.wordpress.org/reference/classes/wp_query/
Editable Regions
An editable region is an area of your site layout
that the user can access and control its content.
For example:
• Menus
• Widgets
A good theme creates editable regions
instead of hard-coding content into the
theme’s PHP files.
Menus
Users can create as many menus as they like, but
the way for a theme to know which one to use is
through Menu Locations.
Themes can define multiple Menu Locations using:
• register_nav_menu ( $location, $description );
• register_nav_menus ( $locations );
Menus associated with those locations can be
displayed using:
• has_nav_menu ( $location )
• wp_nav_menu ( array $args = array() )
Widgets are an indispensable tool which allow
users to add secondary content to their site.
Themes can define multiple Sidebars using:
• register_sidebar( $args )
• register_sidebars( $number, $args )
Widgets associated with those Sidebars can be
displayed using:
• is_active_sidebar( $index )
• dynamic_sidebar( $index )
Sidebars & Widgets
Hooks
A hook is an "event" within WordPress
code which allows for additional code to
be run when it occurs.
One or more functions can be associated
with a hook name and they will all run
when the hook is triggered.
https://codex.wordpress.org/Plugin_API/Hooks
Why Use Hooks?
Hooks are placed within WordPress core,
plugins, and themes to allow
customization by developers without
direct edits of the code.
Hooks are the proper way to alter the
default behavior of code which is not
yours to edit.
Types of Hooks
Action hooks allow you to run extra code at a
certain point within the code.
Examples in WP core include initialization (‘init’),
before main query is run (‘pre_get_posts’),
header (‘wp_head’) or footer (‘wp_footer’) of a
page/post.
Filter hooks allow you to alter data, content,
parameters. A filter hook passes information to
filter function and returns it altered (or not).
Examples in WP code include displaying content,
page/post title, pre-saving content (admin).
Action Hook Example
/*** In WordPress Core, hook is triggered ***/
function wp_head() {
/**
* Print scripts or data in the
* head tag on the front end.
*
* @since 1.5.0
*/
do_action( 'wp_head' );
}
/*** In your code…your function is run ***/
add_action('wp_head', 'mytheme_analytics');
Filter Hook Example
/*** In WordPress Core, hook is triggered ***/
function the_content( ... ) {
$content = get_the_content(
$more_link_text, $strip_teaser );
$content = apply_filters(
'the_content', $content );
...
echo $content;
}
/*** In your code…your function is run ***/
add_filter('the_content', 'replace_trump' );
• WordPress has a built-in system to allow
you to put your style (CSS) and script (JS)
files into a queue to be loaded into the
header or footer of your site.
• Plugins needing the same script can utilize
a single version rather than each loading
their own version.
• This helps prevent conflicts and improves
site performance (fewer scripts loaded).
• When enqueueing styles and scripts you
can also declare dependencies.
Enqueueing
Enqueueing Theme Styles
Within child theme, create functions.php and include
parent theme’s CSS file:
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_styles' );
function mytheme_enqueue_styles() {
//Include parent theme style
wp_enqueue_style(
'parent-style',
get_template_directory_uri() . '/style.css' );
//Include child theme style (dependent on parent style)
wp_enqueue_style(
'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( 'parent-style' )
);
}
Using WordPress as a CMS
CMS = Content Management System
WordPress is already a CMS containing these
Post Types:
Posts Media Items
Pages Menus
Revisions
WordPress can be extended beyond those to
include new Custom Post Types such as:
Events Portfolio Items
Products Resources
Forms Team Members
Taxonomies
Taxonomies are a way of categorizing content.
WordPress is already a CMS containing these
Taxonomies:
Categories
Tags
WordPress can be extended beyond those to
include new Custom Taxonomies such as:
Event Category
Portfolio Medium
Team
Genre
Custom Fields
Custom Fields are a way to track more specific
attributes of content.
Examples of Custom Fields include:
Event Date
Price
Location
Position
Extend WordPress Structure
• Create new Custom Post Types
• Create new Taxonomies
• Create new Custom Fields
Example:
Event Custom Post Type
Event Category Taxonomy
Event Date Custom Field
Event Fee Custom Field
Tools to Extend WordPress
Custom Post Types & Taxonomy plugins:
• Custom Post Type UI
• MasterPress
• Pods
Advanced Meta / Custom Field plugins:
• Advanced Custom Fields
• Custom Field Suite
• CMB2
• Meta Box
Extend WordPress Yourself
• Use register_post_type() to create Custom
Post Types
• Use register_taxonomy () to create Custom
Taxonomies
• Use add_meta_boxes hook to add custom
fields to edit screens and get_post_meta() to
display those fields in your templates.
Check WordPress Code Reference or the Codex
for help on writing those functions or the
GenerateWP website to facilitate writing them.
Shortcodes
Shortcodes are a placeholder mechanism
whereby strings placed in content get replaced in
real-time with other content.
WordPress itself includes shortcodes such as
[gallery] and [embed] as do many plugins.
Themes can include their own shortcodes to help
users display content.
https://codex.wordpress.org/Shortcode_API
Shortcode Example
/*
* Email
*
* Given an email address, it encrypts the mailto
* and the text of the email and returns a proper
* email link which can't be picked up on bots
*/
function mytheme_email_encode( $atts, $content ){
return '<a href="' .
antispambot("mailto:".$content) . '">' .
antispambot($content) . '</a>';
}
add_shortcode( 'email', 'mytheme_email_encode' );
NOTE: Shortcode functions must RETURN content (not echo!)
If I was a Time Lord…
We would also cover:
• Transients API
• Customizer
• Customizing the Admin
• Creating Dashboard Widgets
• Debugging
• Developer Tools
Up Your Game!
• Read Developer Blogs & subscribe to those you
like or follow on Twitter
• Subscribe to updates on Make WordPress Core
• Subscribe to Post Status (WordPress newsletter –
paid service) or other WordPress specific news
sources
• Set aside time each day or week to read
WordPress news or research code
• Use an IDE (Integrated Development
Environment) so you can go right into a core or
plugin function to look for hooks or check
functionality
Resources
Codex: https://codex.wordpress.org/
Theme Handbook:
https://developer.wordpress.org/themes/getting
-started/
Code Reference:
https://developer.wordpress.org/reference/
Thank You!
Amanda Giles
@AmandaGilesNH
www.Amanda Giles.com
Slides: http://amandagiles.com/enlightenment
Background designs are the property of Geetesh Bajaj. Used with
permission. © Copyright, Geetesh Bajaj. All Rights Reserved.

Contenu connexe

Tendances

8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8Logan Farr
 
WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013Curtiss Grymala
 
Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Anne Tomasevich
 
NewBCamp09: Turning your design into a WordPress Theme
NewBCamp09: Turning your design into a WordPress ThemeNewBCamp09: Turning your design into a WordPress Theme
NewBCamp09: Turning your design into a WordPress ThemeAdam Darowski
 
Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingRobert Carr
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic templatevathur
 
Intro to Theming Drupal, FOSSLC Summer Camp 2010
Intro to Theming Drupal, FOSSLC Summer Camp 2010Intro to Theming Drupal, FOSSLC Summer Camp 2010
Intro to Theming Drupal, FOSSLC Summer Camp 2010Emma Jane Hogbin Westby
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress WayMatt Wiebe
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSNaga Harish M
 
Drupal 8 introduction to theming
Drupal 8  introduction to themingDrupal 8  introduction to theming
Drupal 8 introduction to themingBrahampal Singh
 
Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Themingdrubb
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Balázs Tatár
 
Crash Course in Theme Surgery
Crash Course in Theme SurgeryCrash Course in Theme Surgery
Crash Course in Theme SurgeryRational Frank
 
Builing a WordPress Theme
Builing a WordPress ThemeBuiling a WordPress Theme
Builing a WordPress Themecertainstrings
 

Tendances (20)

Mobile themes, QR codes, and shortURLs
Mobile themes, QR codes, and shortURLsMobile themes, QR codes, and shortURLs
Mobile themes, QR codes, and shortURLs
 
Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
Theming 101
Theming 101Theming 101
Theming 101
 
Assetic (OSCON)
Assetic (OSCON)Assetic (OSCON)
Assetic (OSCON)
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8
 
WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013
 
Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8
 
NewBCamp09: Turning your design into a WordPress Theme
NewBCamp09: Turning your design into a WordPress ThemeNewBCamp09: Turning your design into a WordPress Theme
NewBCamp09: Turning your design into a WordPress Theme
 
Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) Theming
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
 
Intro to Theming Drupal, FOSSLC Summer Camp 2010
Intro to Theming Drupal, FOSSLC Summer Camp 2010Intro to Theming Drupal, FOSSLC Summer Camp 2010
Intro to Theming Drupal, FOSSLC Summer Camp 2010
 
Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress Way
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
 
Drupal 8 introduction to theming
Drupal 8  introduction to themingDrupal 8  introduction to theming
Drupal 8 introduction to theming
 
Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Theming
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
 
Crash Course in Theme Surgery
Crash Course in Theme SurgeryCrash Course in Theme Surgery
Crash Course in Theme Surgery
 
Builing a WordPress Theme
Builing a WordPress ThemeBuiling a WordPress Theme
Builing a WordPress Theme
 
Kickass
KickassKickass
Kickass
 

Similaire à The Way to Theme Enlightenment 2017

The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme EnlightenmentAmanda Giles
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4David Bisset
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress themeHardeep Asrani
 
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...LinnAlexandra
 
WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3David Bisset
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
 
Word press templates
Word press templatesWord press templates
Word press templatesDan Phiffer
 
WordPress Theme Design and Development Workshop - Day 2
WordPress Theme Design and Development Workshop - Day 2WordPress Theme Design and Development Workshop - Day 2
WordPress Theme Design and Development Workshop - Day 2Mizanur Rahaman Mizan
 
WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013Curtiss Grymala
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPressNile Flores
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentSitdhibong Laokok
 
Theme development essentials columbus oh word camp 2012
Theme development essentials   columbus oh word camp 2012Theme development essentials   columbus oh word camp 2012
Theme development essentials columbus oh word camp 2012Joe Querin
 
Week 7 introduction to theme development
Week 7   introduction to theme developmentWeek 7   introduction to theme development
Week 7 introduction to theme developmenthenri_makembe
 
WordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteWordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteBrendan Sera-Shriar
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme developmentThad Allender
 
Responsive Theme Workshop - WordCamp Columbus 2015
Responsive Theme Workshop - WordCamp Columbus 2015Responsive Theme Workshop - WordCamp Columbus 2015
Responsive Theme Workshop - WordCamp Columbus 2015Joe Querin
 
Easy Guide to WordPress Theme Integration
Easy Guide to WordPress Theme IntegrationEasy Guide to WordPress Theme Integration
Easy Guide to WordPress Theme IntegrationSankhala Info Solutions
 

Similaire à The Way to Theme Enlightenment 2017 (20)

The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress theme
 
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
 
WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
Word press templates
Word press templatesWord press templates
Word press templates
 
WordPress Theme Design and Development Workshop - Day 2
WordPress Theme Design and Development Workshop - Day 2WordPress Theme Design and Development Workshop - Day 2
WordPress Theme Design and Development Workshop - Day 2
 
WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme Development
 
Theme development essentials columbus oh word camp 2012
Theme development essentials   columbus oh word camp 2012Theme development essentials   columbus oh word camp 2012
Theme development essentials columbus oh word camp 2012
 
Week 7 introduction to theme development
Week 7   introduction to theme developmentWeek 7   introduction to theme development
Week 7 introduction to theme development
 
WordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteWordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media Institute
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme development
 
Responsive Theme Workshop - WordCamp Columbus 2015
Responsive Theme Workshop - WordCamp Columbus 2015Responsive Theme Workshop - WordCamp Columbus 2015
Responsive Theme Workshop - WordCamp Columbus 2015
 
Easy Guide to WordPress Theme Integration
Easy Guide to WordPress Theme IntegrationEasy Guide to WordPress Theme Integration
Easy Guide to WordPress Theme Integration
 

Dernier

TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 

Dernier (11)

TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 

The Way to Theme Enlightenment 2017

  • 1. The Way to Theme Enlightenment Amanda Giles @AmandaGilesNH https://amandagiles.com/enlightenment
  • 2. Who am I? • Programming since 1985 (Basic & Logo!) • Made my first website in 1994 • Professionally coding for 20 years • Independent Consultant since 2006 • Working with WordPress since 2009 • Started the Seacoast NH WordPress Meetup in 2011 • Co-Created Spark Development WordPress Development Agency in 2016
  • 5. Child Themes If you’re editing an existing theme… CREATE A CHILD THEME! • A child theme separates your customizations from the existing theme • Existing theme becomes the “parent” theme • Both themes are installed on your site • Child themes allows for upgrades of the parent theme (without losing customizations!) • WordPress looks to the child theme first for files it needs. If not found, it then looks in the parent theme folder. https://developer.wordpress.org/themes/advanced-topics/child-themes/
  • 6. Child Themes 1. Make a child theme by adding a new folder under wp-content/themes 2. Create style.css with informational header: /* Theme Name: My Child Theme Description: Child theme for John’s company Theme Author: Jane Doe Author URI: http://janedoes.com Template: twentyseventeen */
  • 7. Child Themes 3. Create functions.php and include parent theme’s CSS file: add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_css' ); function mytheme_enqueue_css() { //Include parent theme style wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); //Include child theme style (dependent on parent style) wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ) ); }
  • 8. Template Hierarchy How WordPress determines which template file (in your theme) to use to display a particular page on your website. Called a “hierarchy” because WordPress looks in a specific order (from most specific to least specific) to determine which file to use. Important to understand so you don’t repeat yourself unnecessarily in theme files. Your entire theme could consist of just 2 files: style.css + index.php But that’s not usually the case!
  • 10. Template Hierarchy Example 1. category-$slug.php Variable Template 2. category-$id.php Variable Template 3. category.php Secondary Template 4. archive.php Primary Template 5. index.php Primary Template
  • 11. Useful Theme Functions get_header ( string $name = null ) get_sidebar (string $name = null ) get_footer (string $name = null ) get_template_part ( string $slug, string $name = null ) get_bloginfo ( string $show = '', string $filter = 'raw' )
  • 12. Conditional Tags Examples include: • is_front_page() • is_admin() • is_single() / is_singular() • is_page() / is_page(43) / is_page(‘about’) • Is_page_template() • is_category() / is_category(7) / is_category(‘news’) • is_post_type_archive() • Is_tax() https://developer.wordpress.org/themes/basics/conditional-tags/
  • 13. Content Functions Examples include: the_title() get_the_title() the_permalink() get_the_permalink() the_date() get_the_date() the_post_thumbnail() get_the_post_thumbnail() the_excerpt() get_the_excerpt() the_content() get_the_content() $content = apply_filters('the_content', get_the_content());
  • 14. Functions.php If you have a functions.php file in your active theme directory, WordPress will automatically load this file when viewing both the front and back-end of your website. Within this file, you can write your own functions and call WordPress core or plugin functions. Function names should be unique to avoid conflicts. https://codex.wordpress.org/Functions_File_Explained
  • 15. CSS Classes – body_class() Most WordPress themes use body_class() on the body tag and this gives you a very helpful set of CSS classes. <body <?php body_class(); ?>> <body class="page page-id-89 page-template-default"> <body class="archive category category-news category-1 logged-in admin-bar no-customize-support"> <body class="single single-post postid-247 single- format-standard"> <body class="single single-event postid-3448">
  • 16. CSS Classes – post_class() Many WordPress themes use post_class() on the post <article> tag (single and archive pages) and this gives you a very helpful set of CSS classes. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <article id="post-247" class="post-247 post type-post status-publish format-standard hentry category-news"> <article id="post-7537" class="post-7537 featured- stories type-featured-stories status-publish hentry" >
  • 17. The Loop & WP_Query() “The Loop” is at the heart of all WordPress pages. if ( have_posts() ) : // Start the Loop. while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content', get_post_type() ); endwhile; // End the loop. endif;
  • 18. The Loop & WP_Query() Use WP_Query() to write your own queries to pull content from your WordPress site. Define an array of your query parameters to pass to WP_Query(): <?php //Get 20 Books in alphabetical order by title $args = array( 'post_type' => 'book', 'post_per_page' => 20, 'orderby' => 'title', 'order' => 'ASC' );
  • 19. The Loop & WP_Query() Then pass that array of query arguments to WP_Query(): $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); get_template_part( 'template-parts/content', 'book' ); endwhile; endif; //Restore the $post global to the current post in // the main query – VERY IMPORTANT! wp_reset_postdata();
  • 20. The Loop & WP_Query() Make complex queries using tax_query: $args = array( 'post_type' => 'book', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'genre', 'field' => 'slug', 'operator' => 'IN', 'terms' => 'romance' array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => 'featured' ) ); https://developer.wordpress.org/reference/classes/wp_query/
  • 21. The Loop & WP_Query() Make complex queries using meta_query: $args = array( 'post_type' => 'book', 'meta_query' => array( 'relation' => ‘OR', array( 'key' => 'rating', 'value' => '3', 'compare' => '>=', 'type' => 'numeric', array( 'key' => 'recommended', 'value' => 'Y', 'compare' => '=', ) ); https://developer.wordpress.org/reference/classes/wp_query/
  • 22. Editable Regions An editable region is an area of your site layout that the user can access and control its content. For example: • Menus • Widgets A good theme creates editable regions instead of hard-coding content into the theme’s PHP files.
  • 23. Menus Users can create as many menus as they like, but the way for a theme to know which one to use is through Menu Locations. Themes can define multiple Menu Locations using: • register_nav_menu ( $location, $description ); • register_nav_menus ( $locations ); Menus associated with those locations can be displayed using: • has_nav_menu ( $location ) • wp_nav_menu ( array $args = array() )
  • 24. Widgets are an indispensable tool which allow users to add secondary content to their site. Themes can define multiple Sidebars using: • register_sidebar( $args ) • register_sidebars( $number, $args ) Widgets associated with those Sidebars can be displayed using: • is_active_sidebar( $index ) • dynamic_sidebar( $index ) Sidebars & Widgets
  • 25. Hooks A hook is an "event" within WordPress code which allows for additional code to be run when it occurs. One or more functions can be associated with a hook name and they will all run when the hook is triggered. https://codex.wordpress.org/Plugin_API/Hooks
  • 26. Why Use Hooks? Hooks are placed within WordPress core, plugins, and themes to allow customization by developers without direct edits of the code. Hooks are the proper way to alter the default behavior of code which is not yours to edit.
  • 27. Types of Hooks Action hooks allow you to run extra code at a certain point within the code. Examples in WP core include initialization (‘init’), before main query is run (‘pre_get_posts’), header (‘wp_head’) or footer (‘wp_footer’) of a page/post. Filter hooks allow you to alter data, content, parameters. A filter hook passes information to filter function and returns it altered (or not). Examples in WP code include displaying content, page/post title, pre-saving content (admin).
  • 28. Action Hook Example /*** In WordPress Core, hook is triggered ***/ function wp_head() { /** * Print scripts or data in the * head tag on the front end. * * @since 1.5.0 */ do_action( 'wp_head' ); } /*** In your code…your function is run ***/ add_action('wp_head', 'mytheme_analytics');
  • 29. Filter Hook Example /*** In WordPress Core, hook is triggered ***/ function the_content( ... ) { $content = get_the_content( $more_link_text, $strip_teaser ); $content = apply_filters( 'the_content', $content ); ... echo $content; } /*** In your code…your function is run ***/ add_filter('the_content', 'replace_trump' );
  • 30. • WordPress has a built-in system to allow you to put your style (CSS) and script (JS) files into a queue to be loaded into the header or footer of your site. • Plugins needing the same script can utilize a single version rather than each loading their own version. • This helps prevent conflicts and improves site performance (fewer scripts loaded). • When enqueueing styles and scripts you can also declare dependencies. Enqueueing
  • 31. Enqueueing Theme Styles Within child theme, create functions.php and include parent theme’s CSS file: add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_styles' ); function mytheme_enqueue_styles() { //Include parent theme style wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); //Include child theme style (dependent on parent style) wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ) ); }
  • 32. Using WordPress as a CMS CMS = Content Management System WordPress is already a CMS containing these Post Types: Posts Media Items Pages Menus Revisions WordPress can be extended beyond those to include new Custom Post Types such as: Events Portfolio Items Products Resources Forms Team Members
  • 33. Taxonomies Taxonomies are a way of categorizing content. WordPress is already a CMS containing these Taxonomies: Categories Tags WordPress can be extended beyond those to include new Custom Taxonomies such as: Event Category Portfolio Medium Team Genre
  • 34. Custom Fields Custom Fields are a way to track more specific attributes of content. Examples of Custom Fields include: Event Date Price Location Position
  • 35. Extend WordPress Structure • Create new Custom Post Types • Create new Taxonomies • Create new Custom Fields Example: Event Custom Post Type Event Category Taxonomy Event Date Custom Field Event Fee Custom Field
  • 36. Tools to Extend WordPress Custom Post Types & Taxonomy plugins: • Custom Post Type UI • MasterPress • Pods Advanced Meta / Custom Field plugins: • Advanced Custom Fields • Custom Field Suite • CMB2 • Meta Box
  • 37. Extend WordPress Yourself • Use register_post_type() to create Custom Post Types • Use register_taxonomy () to create Custom Taxonomies • Use add_meta_boxes hook to add custom fields to edit screens and get_post_meta() to display those fields in your templates. Check WordPress Code Reference or the Codex for help on writing those functions or the GenerateWP website to facilitate writing them.
  • 38. Shortcodes Shortcodes are a placeholder mechanism whereby strings placed in content get replaced in real-time with other content. WordPress itself includes shortcodes such as [gallery] and [embed] as do many plugins. Themes can include their own shortcodes to help users display content. https://codex.wordpress.org/Shortcode_API
  • 39. Shortcode Example /* * Email * * Given an email address, it encrypts the mailto * and the text of the email and returns a proper * email link which can't be picked up on bots */ function mytheme_email_encode( $atts, $content ){ return '<a href="' . antispambot("mailto:".$content) . '">' . antispambot($content) . '</a>'; } add_shortcode( 'email', 'mytheme_email_encode' ); NOTE: Shortcode functions must RETURN content (not echo!)
  • 40. If I was a Time Lord… We would also cover: • Transients API • Customizer • Customizing the Admin • Creating Dashboard Widgets • Debugging • Developer Tools
  • 41. Up Your Game! • Read Developer Blogs & subscribe to those you like or follow on Twitter • Subscribe to updates on Make WordPress Core • Subscribe to Post Status (WordPress newsletter – paid service) or other WordPress specific news sources • Set aside time each day or week to read WordPress news or research code • Use an IDE (Integrated Development Environment) so you can go right into a core or plugin function to look for hooks or check functionality
  • 43.
  • 44.
  • 45.
  • 46.
  • 47. Thank You! Amanda Giles @AmandaGilesNH www.Amanda Giles.com Slides: http://amandagiles.com/enlightenment Background designs are the property of Geetesh Bajaj. Used with permission. © Copyright, Geetesh Bajaj. All Rights Reserved.