SlideShare a Scribd company logo
The Way to
Theme Enlightenment
Amanda Giles
@AmandaGilesNH
http://amandagiles.com/enlightenment
Who am I?
โ€ข Programmer 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
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,
USE A CHILD THEME!
The existing theme becomes your โ€œparentโ€ theme
and both themes are installed on your site.
A child theme separates your changes from the
underlying theme, allowing for upgrades of the
parent theme or support from the theme maker.
WordPress looks to the child theme first for files it
needs. If not found, it then looks in the parent.
https://codex.wordpress.org/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: Johnโ€™s New Theme
Theme URI: http://janedoes.com/johns-theme/
Description: Child theme for Johnโ€™s company
Theme Author: Jane Doe
Author URI: http://janedoes.com
Template: twentysixteen
*/
Child Themes
3. Create functions.php and include parent themeโ€™s
CSS file:
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_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' )
);
}
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. paged.php Secondary Template
6. 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_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_format()
);
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',
'tax_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', 'show_my_fonts_css');
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 even declare dependencies.
Enqueueing
Enqueueing Theme Styles
Within child theme, create functions.php and include
parent themeโ€™s CSS file:
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_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 The Whip newsletter by WPMU
โ€ข Subscribe to updates on Make WordPress Core
โ€ข Subscribe to Post Status (WordPress newsletter โ€“
paid service)
โ€ข 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/
The Way to Theme Enlightenment
The Way to Theme Enlightenment
The Way to Theme Enlightenment
The Way to Theme Enlightenment
The Way to Theme Enlightenment
The Way to Theme Enlightenment
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.

More Related Content

PPTX
Creating Customizable Widgets for Unpredictable Needs
PPTX
Shortcodes vs Widgets: Which one and how?
PPTX
WordPress Theme Development: Part 2
PPTX
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
PPTX
Custom WordPress theme development
PDF
WordPress Theme Development for Designers
PPT
WordPress Child Themes
KEY
WordPress Developers Israel Meetup #1
Creating Customizable Widgets for Unpredictable Needs
Shortcodes vs Widgets: Which one and how?
WordPress Theme Development: Part 2
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
Custom WordPress theme development
WordPress Theme Development for Designers
WordPress Child Themes
WordPress Developers Israel Meetup #1

What's hot (20)

PDF
Intro to WordPress theme development
PDF
WordPress Theme Structure
PDF
Becoming a better WordPress Developer
PPTX
Rebrand WordPress Admin
PPTX
Responsive Theme Workshop - WordCamp Columbus 2015
KEY
Custom Post Types in Depth at WordCamp Montreal
PDF
Seven deadly theming sins
PDF
Introduction to WordPress Theme Development
PPTX
Introduction to Custom WordPress Themeing
PPTX
Theme development essentials columbus oh word camp 2012
PDF
Theming 101
PDF
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
PDF
Theming Wordpress with Adobe
PDF
How to Prepare a WordPress Theme for Public Release
PPTX
Build a WordPress theme from HTML5 template @ Telerik
PDF
WordPress Theme Development
PDF
Custom Fields & Custom Metaboxes Overview
PPTX
Demystifying WordPress Conditional Tags
PPT
WordCamp Boston 2012 - Creating Content With Shortcodes
PDF
Cms & wordpress theme development 2011
Intro to WordPress theme development
WordPress Theme Structure
Becoming a better WordPress Developer
Rebrand WordPress Admin
Responsive Theme Workshop - WordCamp Columbus 2015
Custom Post Types in Depth at WordCamp Montreal
Seven deadly theming sins
Introduction to WordPress Theme Development
Introduction to Custom WordPress Themeing
Theme development essentials columbus oh word camp 2012
Theming 101
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Theming Wordpress with Adobe
How to Prepare a WordPress Theme for Public Release
Build a WordPress theme from HTML5 template @ Telerik
WordPress Theme Development
Custom Fields & Custom Metaboxes Overview
Demystifying WordPress Conditional Tags
WordCamp Boston 2012 - Creating Content With Shortcodes
Cms & wordpress theme development 2011
Ad

Similar to The Way to Theme Enlightenment (20)

PPTX
The Way to Theme Enlightenment 2017
PPTX
Childthemes ottawa-word camp-1919
PDF
WordPress Theming 101
PDF
WordPress Theme Workshop: Part 4
PDF
How to make a WordPress theme
PDF
WordPress Theme Workshop: Part 3
PPTX
Building Potent WordPress Websites
PPTX
WordPress Structure and Best Practices
PDF
Best Wordprees development company in bangalore
PDF
Website development PDF which helps others make it easy
PPTX
PSD to WordPress
PDF
Word press templates
PPTX
Getting started with WordPress development
PPTX
WordPress Themes 101 - dotEduGuru Summit 2013
PPSX
WordPress Theme Design and Development Workshop - Day 2
PPT
WordPress 2.5 Overview - Rich Media Institute
PPT
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
PPTX
Customizing WordPress Themes
PPT
Week 7 introduction to theme development
PDF
Intro to WordPress Plugin Development
The Way to Theme Enlightenment 2017
Childthemes ottawa-word camp-1919
WordPress Theming 101
WordPress Theme Workshop: Part 4
How to make a WordPress theme
WordPress Theme Workshop: Part 3
Building Potent WordPress Websites
WordPress Structure and Best Practices
Best Wordprees development company in bangalore
Website development PDF which helps others make it easy
PSD to WordPress
Word press templates
Getting started with WordPress development
WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Theme Design and Development Workshop - Day 2
WordPress 2.5 Overview - Rich Media Institute
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Customizing WordPress Themes
Week 7 introduction to theme development
Intro to WordPress Plugin Development
Ad

Recently uploaded (20)

PDF
โ€œGoogle Algorithm Updates in 2025 Guideโ€
PPTX
Digital Literacy And Online Safety on internet
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
๐Ÿ’ฐ ๐”๐Š๐“๐ˆ ๐Š๐„๐Œ๐„๐๐€๐๐†๐€๐ ๐Š๐ˆ๐๐„๐‘๐Ÿ’๐ƒ ๐‡๐€๐‘๐ˆ ๐ˆ๐๐ˆ ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ“ ๐Ÿ’ฐ
ย 
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Internet___Basics___Styled_ presentation
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
Vigrab.top โ€“ Online Tool for Downloading and Converting Social Media Videos a...
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
artificial intelligence overview of it and more
PPTX
durere- in cancer tu ttresjjnklj gfrrjnrs mhugyfrd
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPT
tcp ip networks nd ip layering assotred slides
โ€œGoogle Algorithm Updates in 2025 Guideโ€
Digital Literacy And Online Safety on internet
PptxGenJS_Demo_Chart_20250317130215833.pptx
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
SAP Ariba Sourcing PPT for learning material
An introduction to the IFRS (ISSB) Stndards.pdf
๐Ÿ’ฐ ๐”๐Š๐“๐ˆ ๐Š๐„๐Œ๐„๐๐€๐๐†๐€๐ ๐Š๐ˆ๐๐„๐‘๐Ÿ’๐ƒ ๐‡๐€๐‘๐ˆ ๐ˆ๐๐ˆ ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ“ ๐Ÿ’ฐ
ย 
QR Codes Qr codecodecodecodecocodedecodecode
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Internet___Basics___Styled_ presentation
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Vigrab.top โ€“ Online Tool for Downloading and Converting Social Media Videos a...
WebRTC in SignalWire - troubleshooting media negotiation
Decoding a Decade: 10 Years of Applied CTI Discipline
522797556-Unit-2-Temperature-measurement-1-1.pptx
artificial intelligence overview of it and more
durere- in cancer tu ttresjjnklj gfrrjnrs mhugyfrd
Job_Card_System_Styled_lorem_ipsum_.pptx
Introuction about WHO-FIC in ICD-10.pptx
tcp ip networks nd ip layering assotred slides

The Way to Theme Enlightenment

  • 1. The Way to Theme Enlightenment Amanda Giles @AmandaGilesNH http://amandagiles.com/enlightenment
  • 2. Who am I? โ€ข Programmer 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
  • 5. Child Themes If youโ€™re editing an existing theme, USE A CHILD THEME! The existing theme becomes your โ€œparentโ€ theme and both themes are installed on your site. A child theme separates your changes from the underlying theme, allowing for upgrades of the parent theme or support from the theme maker. WordPress looks to the child theme first for files it needs. If not found, it then looks in the parent. https://codex.wordpress.org/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: Johnโ€™s New Theme Theme URI: http://janedoes.com/johns-theme/ Description: Child theme for Johnโ€™s company Theme Author: Jane Doe Author URI: http://janedoes.com Template: twentysixteen */
  • 7. Child Themes 3. Create functions.php and include parent themeโ€™s CSS file: add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_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' ) ); }
  • 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. paged.php Secondary Template 6. 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_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_format() ); 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', 'tax_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', 'show_my_fonts_css');
  • 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 even 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', 'theme_enqueue_styles' ); function theme_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 The Whip newsletter by WPMU โ€ข Subscribe to updates on Make WordPress Core โ€ข Subscribe to Post Status (WordPress newsletter โ€“ paid service) โ€ข 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
  • 49. 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.