SlideShare a Scribd company logo
WordPress Theming 101
“..a collection of files that work together to
produce a graphical interface with an underlying
unifying design for a weblog. These files are called
template files.
A Theme modifies the way the site is displayed,
without modifying the underlying software.”
Ref: https://codex.wordpress.org/Using_Themes
Provides front end styling for page areas &
content
• header, footer and logo areas
• fonts & colors
• widget and sidebar locations
• page layouts (or templates)
• styles for blog posts and blog archives
• additional stylistic details and custom post types
1,000’s of free themes at wordpress.org/themes
all human vetted and all safe (no malware).
Paid themes:
• Themeforest
• Elegant Themes
• StudioPress
There are many more paid sites – we vouch for these 3
You can have a unique theme built for your site.
We know a theme is a collection of files.
Which files do what?
How do they work together to “theme” your site?
In a default installation all themes reside in the
folder: /wp-content/themes/<unique_theme_name>
However, this folder path can be changed at a
site level. Use functions in theme code to find
the correct folder.
get_template_directory_uri() get_template_directory()
get_stylesheet_directory_uri() get_stylesheet_directory()
get_theme_root_uri() get_theme_root()
get_stylesheet_uri()
get_theme_roots()
Ref: https://codex.wordpress.org/Determining_Plugin_and_Content_Directories#Themes
Ref: https://developer.wordpress.org/themes/basics/template-hierarchy/
Main types of theme template files are:
• .php = PHP language files used to build
template structure and output content
(required)
• .css = Style sheet files used to apply style to
template structure and content (required)
• .js = JavaScript files used for real-time user
interface (UI) interaction & manipulation and
much more (optional)
Ref: https://developer.wordpress.org/themes/basics/template-hierarchy/
A web server converts/renders PHP files to a
static HTML page which is sent to the browser
along with any corresponding CSS and other
asset files such as images.
Static HTML pages rendered from PHP files
cannot interact with the user in the browser no
matter how much they wiggle, move or click
their mouse pointer at things on the page.
Ref: https://developer.wordpress.org/themes/basics/template-hierarchy/
JavaScript runs in the browser and detects
“events” such as window resize, mouse
overs/movement/clicks, field
selections/changes/input etc.
JavaScript functions are bound to browser
events allowing the HTML and CSS of the static
page to now be changed dynamically in
response to that event.
Most important template file.
Your theme must have an index.php
This is the main blog article archive/page and top
of the hierarchy (last to render)
If there are no other php template files, index.php
will be used to render the current web page.
Ref: https://developer.wordpress.org/themes/basics/template-hierarchy/
2nd most important theme file.
Your theme must have a style.css
This file contains the theme name, version,
description and license type that is displayed on
the Appearance > Themes dashboard panel.
Other primary templates are:
• archive.php
The archive template is used when visitors request posts by
category, author, or date.
• single.php
The single post template is used when a visitor requests a single
post.
• page.php
The page template is used when visitors request individual
pages, which are a built-in template.
Other primary templates are:
• singular.php
The singular template is used for posts when single.php is not
found, or for pages when page.php are not found.
• home.php
The home page template is the front page by default. If you do
not set WordPress to use a static front page, this template is
used to show latest posts.
• front-page.php
The front page template is always used as the site front page if it
exists, regardless of what settings on Admin > Settings > Reading.
Other primary templates are:
• comments.php
The comments template.
• 404.php
The 404 template is used when WordPress cannot find a post,
page, or other content that matches the visitor’s request.
• search.php
The search results template is used to display a visitor’s search
results.
Needs to be in the root directory of your theme.
/wp-content/themes/<unique_theme_name>/style.css
WordPress uses the header comment section of a
style.css to display information about the theme
in the Appearance > Themes dashboard panel.
These header comments in style.css are required.
There are more you can use.
/*
Theme Name: Twenty Sixteen
Author: the WordPress Team
Description: Twenty Sixteen is a modernised take on an ever-
popular WordPress layout
Version: 1.3
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twentysixteen
*/
Ref: https://developer.wordpress.org/themes/basics/main-stylesheet-style-css/
WordPress Theming 101
There is no official required
theme folder structure.
Here’s an example based on
Twenty Sixteen.
Primary template files are
located in the root of your
theme folder.
Assets are in a separate sub
folder.
assets (dir)
- css (dir)
- images (dir)
- js (dir)
template-parts (dir)
- footer (dir)
- header (dir)
- navigation (dir)
- page (dir)
- post (dir)
404.php
archive.php
footer.php
front-page.php
functions.php
header.php
index.php
page.php
README.txt
rtl.css
screenshot.png
single.php
style.css
Template tags are used within themes to retrieve
content from your database.
They help you to avoid hard coding content into
template files.
A template tag is broken up into three parts:
• A PHP code tag
• A WordPress function
• Optional parameters
Ref: https://developer.wordpress.org/themes/basics/template-tags/
Printing the header.php file using get_header():
<?php get_header(); ?>
Printing the blog site title (Settings > General):
<?php bloginfo(‘name’); ?>
Other template tags:
the_content() the_excerpt()
next_post() previous_post()
The Loop is the default mechanism WordPress
uses for outputting posts through a theme’s
template files.
The Loop extracts the data for each post from the
WordPress database and inserts the appropriate
information in place of each template tag. Any
HTML or PHP code in The Loop will be processed
for each post.
Ref: https://developer.wordpress.org/themes/basics/the-loop/
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
the_content();
endwhile;
else :
_e( 'Sorry, no posts matched your criteria.',
'textdomain' );
endif;
The functions.php file is where you add unique
features to your WordPress theme.
It can be used to hook into the core functions of
WordPress to make your theme more modular,
extensible, and functional.
Each theme has its own functions file, but only
code in the active theme’s functions.php is
actually run. If your theme already has a functions
file, you can add code to it.
Ref: https://developer.wordpress.org/themes/basics/theme-functions/
if ( ! function_exists( 'myfirsttheme_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*/
function myfirsttheme_setup() {
/**
* Make theme available for translation.
* Translations can be placed in the /languages/ directory.
*/
load_theme_textdomain( 'myfirsttheme', get_template_directory() . '/languages' );
}
endif; // myfirsttheme_setup
add_action( 'after_setup_theme', 'myfirsttheme_setup' );
Ref: https://developer.wordpress.org/themes/basics/theme-functions/
You may want to create additional style sheet or
JavaScript files to enhance your theme.
The proper way to add scripts and styles to your
theme is to enqueue them in the functions.php
file.
You do not add them manually to the header.php
file as you would with an HTML page.
Ref: https://developer.wordpress.org/themes/basics/including-css-javascript
Function:
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Parameters:
• $handle is simply the name of the stylesheet.
• $src is where it is located. The rest of the parameters are optional.
• $deps refers to whether or not this stylesheet is dependent on another
stylesheet. If this is set, this stylesheet will not be loaded unless its dependent
stylesheet is loaded first.
• $ver sets the version number.
• $media specify type of media to load, such as ‘all’, ‘screen’, or ‘print’
Basic function use:
wp_enqueue_style( 'style', get_stylesheet_uri() );
Function:
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
Parameters:
• $handle is simply the name of the script.
• $src is where it is located. The rest of the parameters are optional.
• $deps is an array that can handle any script that your new script depends on,
such as jQuery.
• $ver sets the version number.
• $in_footer is a boolean parameter (true/false) that allows you to place your
scripts in the footer of your HTML document rather then in the header
Basic function use:
wp_enqueue_script( script', get_template_directory_uri() );
Styles and scripts are usually loaded on an action
hook. E.g.
/**
* Proper way to enqueue scripts and styles
*/
function wpdocs_theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() .
'/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
Can be used in your template files to alter the
display of content depending on the conditions
that the current page matches.
Display a different greeting for logged in/out users.
if ( is_user_logged_in() ):
echo 'Welcome, registered user!';
else:
echo 'Welcome, visitor!';
endif;
Ref: https://developer.wordpress.org/themes/basics/conditional-tags/
Developing your theme, so it can easily be
translated into other languages.
To make a string translatable you have to wrap the
original strings in a set of special functions that
use your uniquely defined text domain.
The text domain is a unique identifier, which
makes sure WordPress can distinguish between all
loaded translations.
Ref: https://developer.wordpress.org/themes/functionality/internationalization/
Rather than use English only output:
echo 'Your city is $city.‘
Run it through the __() PHP gettext library for
translation using the my-theme text domain:
printf(
__( 'Your city is %s.', 'my-theme' ),
$city
);
A child theme allows you to change small aspects
of your site’s appearance yet still preserve your
theme’s look and functionality.
Parent Theme
A parent theme is a complete theme which
includes all of the required WordPress template
files and assets for the theme to work
Ref: https://developer.wordpress.org/themes/advanced-topics/child-themes/
Inherits the look and feel of the parent theme and
all of its functions, but can be used to make
modifications to any part of the theme.
In this way, customizations are kept separate from
the parent theme’s files.
Using a child theme lets you upgrade/override the
parent theme without affecting the customizations
you’ve made to your site.
Example:
You may have bought a premium theme and
created a child theme to tweak a few styles and
pages.
A major bug is found in the parent theme and
fixed by the author.
An update is available in the dashboard.
Example continued…
You update the parent successfully.
Your changes in the child theme are not deleted
and still override the newly updated parent
theme.
Had you changed the parent theme, your changes
would have been lost with the new update.
WordPress theme frameworks are intended to be
used as parent themes to aid the development of
a child theme.
They contain all the basic structures and
functionalities you would need to create a theme
but lack the styling and completeness you would
expect to find in a working theme for a website.
Ref: https://codex.wordpress.org/Theme_Frameworks
As a parent theme, the framework can be updated
to add new features and fix issues.
Customizations to the child theme, hence the
actual website, remain separate and unchanged,
inheriting the new features and receiving
framework issue fixes.
Developers like using frameworks for consistency
across sites and access to a larger community of
other skilled framework developers.
A popular commercial framework is Genesis.
Other frameworks include:
• Headway (drag & drop)
• Divi (drag & drop)
• Themify
• Beans
• Unyson
Consider theme security as you add functionality.
• Don’t trust any data. Validate all input from
users, 3rd party APIs and the database and
sanitize (escape) data before use or output.
• Use WordPress API functions first. Core
WordPress functions provide functionality of
validating and sanitizing data.
• Keep your theme up to date. Technology
evolves and bugs get found and fixed over time.
Ref: https://developer.wordpress.org/themes/theme-security/
A theme must meet certain requirements to be
included in the WordPress.org theme repository.
Adhering to these requirements is best practice for
theme development even if you don’t intend to
submit to the repository at WordPress.org
Accessibility, Code Quality, Use of Core Features,
Documentation, Language, Licensing, etc…
Ref: https://make.wordpress.org/themes/handbook/review/required/
Themes are reviewed by the Theme Review Team.
Before uploading, your theme must adhere to
• Theme Review Guidelines
• Testing With Sample Data
• Theme Check Plugin
Read the actual review process the team uses.
Ref: https://developer.wordpress.org/themes/release/submitting-your-theme-to-wordpress-org/
The most important thing about designing and
developing a theme is that you have fun doing it!
[Cover/Background] marktimemedia.com
[9] marktimemedia.com
[10] marktimemedia.com
[43] imgur.com
[Back Cover] zeropointdevelopment.com
 20+ years in IT: Dev & SysOps
 WordPress Developer since 2008
 Plugins, APIs, Security & Systems Integrations
 Organiser WPSyd & WordCamp Sydney
zeropointdevelopment.com
@DeveloperWil
♥ Pizza & Craft Beer
WordPress Theming 101

More Related Content

What's hot (18)

PPTX
Building Potent WordPress Websites
Kyle Cearley
 
PDF
Word press templates
Dan Phiffer
 
PDF
skintutorial
tutorialsruby
 
KEY
Doing Things the WordPress Way
Matt Wiebe
 
DOC
Creating a Simple PHP and MySQL-Based Login System
Azharul Haque Shohan
 
PPTX
Introduction to Plugin Programming, WordCamp Miami 2011
David Carr
 
PPTX
Introduction to Custom WordPress Themeing
Jamie Schmid
 
PPTX
Drupal Theme Development
Web Development Montreal
 
PPT
New: Two Methods of Installing Drupal on Windows XP with XAMPP
Rupesh Kumar
 
PPTX
Advanced Intro to Wordpress
Clique Studios
 
PPT
20100622 e z_find_slides_gig_v2.1
Gilles Guirand
 
PDF
Crash Course in Theme Surgery
Rational Frank
 
PPT
Css
NIRMAL FELIX
 
KEY
HTML CSS & Javascript
David Lindkvist
 
PPTX
Rest and Sling Resolution
DEEPAK KHETAWAT
 
PDF
Creating Your First WordPress Plugin
Brad Williams
 
PPT
Apache
NIRMAL FELIX
 
PPT
Php intro
Jennie Gajjar
 
Building Potent WordPress Websites
Kyle Cearley
 
Word press templates
Dan Phiffer
 
skintutorial
tutorialsruby
 
Doing Things the WordPress Way
Matt Wiebe
 
Creating a Simple PHP and MySQL-Based Login System
Azharul Haque Shohan
 
Introduction to Plugin Programming, WordCamp Miami 2011
David Carr
 
Introduction to Custom WordPress Themeing
Jamie Schmid
 
Drupal Theme Development
Web Development Montreal
 
New: Two Methods of Installing Drupal on Windows XP with XAMPP
Rupesh Kumar
 
Advanced Intro to Wordpress
Clique Studios
 
20100622 e z_find_slides_gig_v2.1
Gilles Guirand
 
Crash Course in Theme Surgery
Rational Frank
 
HTML CSS & Javascript
David Lindkvist
 
Rest and Sling Resolution
DEEPAK KHETAWAT
 
Creating Your First WordPress Plugin
Brad Williams
 
Apache
NIRMAL FELIX
 
Php intro
Jennie Gajjar
 

Viewers also liked (12)

PDF
WordPress News - March 2017
WordPress Sydney
 
PDF
WordPress News - February 2017
WordPress Sydney
 
PPTX
WordPress Security Best Practices
Zero Point Development
 
PPTX
Five Minute SEO
WordPress Sydney User Group
 
PDF
Scaling WordPress for High Traffic - Server Architecture
Zero Point Development
 
PDF
Monetising WordPress
Zero Point Development
 
PDF
Understanding Open Source & GPL
Zero Point Development
 
PDF
Setting up a local WordPress development environment
Zero Point Development
 
PDF
Choosing the best hosting package for WordPress
Zero Point Development
 
PDF
23 Ways To Speed Up WordPress
Zero Point Development
 
PPTX
Tips for Fixing a Hacked WordPress Site - WordCamp Sydney 2016
Vlad Lasky
 
PDF
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
WordPress News - March 2017
WordPress Sydney
 
WordPress News - February 2017
WordPress Sydney
 
WordPress Security Best Practices
Zero Point Development
 
Scaling WordPress for High Traffic - Server Architecture
Zero Point Development
 
Monetising WordPress
Zero Point Development
 
Understanding Open Source & GPL
Zero Point Development
 
Setting up a local WordPress development environment
Zero Point Development
 
Choosing the best hosting package for WordPress
Zero Point Development
 
23 Ways To Speed Up WordPress
Zero Point Development
 
Tips for Fixing a Hacked WordPress Site - WordCamp Sydney 2016
Vlad Lasky
 
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
Ad

Similar to WordPress Theming 101 (20)

PPTX
WordPress Themes 101 - HighEdWeb New England 2013
Curtiss Grymala
 
PPTX
WordPress Themes 101 - dotEduGuru Summit 2013
Curtiss Grymala
 
PPSX
WordPress Theme Design and Development Workshop - Day 2
Mizanur Rahaman Mizan
 
PDF
Arizona WP - Building a WordPress Theme
certainstrings
 
PDF
WordPress Theme Workshop: Part 2
David Bisset
 
PDF
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
LinnAlexandra
 
PPTX
WordPress Themes 101 - PSUWeb13 Workshop
Curtiss Grymala
 
PPTX
WordPress Themes and Plugins
superann
 
PPTX
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Curtiss Grymala
 
PPTX
Overview on WordPress theme file structure and working functionality
Rakesh Kushwaha
 
PPTX
Design todevelop
Jason Yingling
 
PDF
WordPress Theme Workshop: Part 3
David Bisset
 
PPT
W pthemes
Becky Davis
 
PDF
Anatomy of a Wordpress theme
Dave Wallace
 
PDF
Dissecting WordPress Themes and Page Templates, WordPress Columbus Meetup
Angela Meeker
 
PPT
WordPress Theme Design - Rich Media Institute Workshop
Brendan Sera-Shriar
 
PPTX
Starting WordPress Theme Review
Catch Themes
 
PPTX
Wordpress theme development
Naeem Junejo
 
KEY
Intro To WordPress Themes
damonsharp
 
PPTX
Themes 101
Jacob Martella
 
WordPress Themes 101 - HighEdWeb New England 2013
Curtiss Grymala
 
WordPress Themes 101 - dotEduGuru Summit 2013
Curtiss Grymala
 
WordPress Theme Design and Development Workshop - Day 2
Mizanur Rahaman Mizan
 
Arizona WP - Building a WordPress Theme
certainstrings
 
WordPress Theme Workshop: Part 2
David Bisset
 
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
LinnAlexandra
 
WordPress Themes 101 - PSUWeb13 Workshop
Curtiss Grymala
 
WordPress Themes and Plugins
superann
 
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Curtiss Grymala
 
Overview on WordPress theme file structure and working functionality
Rakesh Kushwaha
 
Design todevelop
Jason Yingling
 
WordPress Theme Workshop: Part 3
David Bisset
 
W pthemes
Becky Davis
 
Anatomy of a Wordpress theme
Dave Wallace
 
Dissecting WordPress Themes and Page Templates, WordPress Columbus Meetup
Angela Meeker
 
WordPress Theme Design - Rich Media Institute Workshop
Brendan Sera-Shriar
 
Starting WordPress Theme Review
Catch Themes
 
Wordpress theme development
Naeem Junejo
 
Intro To WordPress Themes
damonsharp
 
Themes 101
Jacob Martella
 
Ad

Recently uploaded (20)

PPTX
MSadfadsfafdadfccadradfT_Presentation.pptx
pahalaedward2
 
PPTX
Blue and Dark Blue Modern Technology Presentation.pptx
ap177979
 
PDF
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
PDF
GEO Strategy 2025: Complete Presentation Deck for AI-Powered Customer Acquisi...
Zam Man
 
PPTX
B2B_Ecommerce_Internship_Simranpreet.pptx
LipakshiJindal
 
PPT
Introduction to dns domain name syst.ppt
MUHAMMADKAVISHSHABAN
 
PPTX
The Latest Scam Shocking the USA in 2025.pptx
onlinescamreport4
 
PDF
Cybersecurity Awareness Presentation ppt.
banodhaharshita
 
PPTX
办理方法西班牙假毕业证蒙德拉贡大学成绩单MULetter文凭样本
xxxihn4u
 
PPTX
Artificial-Intelligence-in-Daily-Life (2).pptx
nidhigoswami335
 
DOCX
An_Operating_System by chidi kingsley wo
kingsleywokocha4
 
PDF
Latest Scam Shocking the USA in 2025.pdf
onlinescamreport4
 
PPTX
The Monk and the Sadhurr and the story of how
BeshoyGirgis2
 
PDF
UI/UX Developer Guide: Tools, Trends, and Tips for 2025
Penguin peak
 
PPTX
Different Generation Of Computers .pptx
divcoder9507
 
PDF
LOGENVIDAD DANNYFGRETRRTTRRRTRRRRRRRRR.pdf
juan456ytpro
 
PDF
The AI Trust Gap: Consumer Attitudes to AI-Generated Content
Exploding Topics
 
PPT
1965 INDO PAK WAR which Pak will never forget.ppt
sanjaychief112
 
PPTX
Perkembangan Perangkat jaringan komputer dan telekomunikasi 3.pptx
Prayudha3
 
PPTX
How tech helps people in the modern era.
upadhyayaryan154
 
MSadfadsfafdadfccadradfT_Presentation.pptx
pahalaedward2
 
Blue and Dark Blue Modern Technology Presentation.pptx
ap177979
 
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
GEO Strategy 2025: Complete Presentation Deck for AI-Powered Customer Acquisi...
Zam Man
 
B2B_Ecommerce_Internship_Simranpreet.pptx
LipakshiJindal
 
Introduction to dns domain name syst.ppt
MUHAMMADKAVISHSHABAN
 
The Latest Scam Shocking the USA in 2025.pptx
onlinescamreport4
 
Cybersecurity Awareness Presentation ppt.
banodhaharshita
 
办理方法西班牙假毕业证蒙德拉贡大学成绩单MULetter文凭样本
xxxihn4u
 
Artificial-Intelligence-in-Daily-Life (2).pptx
nidhigoswami335
 
An_Operating_System by chidi kingsley wo
kingsleywokocha4
 
Latest Scam Shocking the USA in 2025.pdf
onlinescamreport4
 
The Monk and the Sadhurr and the story of how
BeshoyGirgis2
 
UI/UX Developer Guide: Tools, Trends, and Tips for 2025
Penguin peak
 
Different Generation Of Computers .pptx
divcoder9507
 
LOGENVIDAD DANNYFGRETRRTTRRRTRRRRRRRRR.pdf
juan456ytpro
 
The AI Trust Gap: Consumer Attitudes to AI-Generated Content
Exploding Topics
 
1965 INDO PAK WAR which Pak will never forget.ppt
sanjaychief112
 
Perkembangan Perangkat jaringan komputer dan telekomunikasi 3.pptx
Prayudha3
 
How tech helps people in the modern era.
upadhyayaryan154
 

WordPress Theming 101

  • 2. “..a collection of files that work together to produce a graphical interface with an underlying unifying design for a weblog. These files are called template files. A Theme modifies the way the site is displayed, without modifying the underlying software.” Ref: https://codex.wordpress.org/Using_Themes
  • 3. Provides front end styling for page areas & content • header, footer and logo areas • fonts & colors • widget and sidebar locations • page layouts (or templates) • styles for blog posts and blog archives • additional stylistic details and custom post types
  • 4. 1,000’s of free themes at wordpress.org/themes all human vetted and all safe (no malware). Paid themes: • Themeforest • Elegant Themes • StudioPress There are many more paid sites – we vouch for these 3
  • 5. You can have a unique theme built for your site. We know a theme is a collection of files. Which files do what? How do they work together to “theme” your site?
  • 6. In a default installation all themes reside in the folder: /wp-content/themes/<unique_theme_name> However, this folder path can be changed at a site level. Use functions in theme code to find the correct folder. get_template_directory_uri() get_template_directory() get_stylesheet_directory_uri() get_stylesheet_directory() get_theme_root_uri() get_theme_root() get_stylesheet_uri() get_theme_roots() Ref: https://codex.wordpress.org/Determining_Plugin_and_Content_Directories#Themes
  • 7. Ref: https://developer.wordpress.org/themes/basics/template-hierarchy/ Main types of theme template files are: • .php = PHP language files used to build template structure and output content (required) • .css = Style sheet files used to apply style to template structure and content (required) • .js = JavaScript files used for real-time user interface (UI) interaction & manipulation and much more (optional)
  • 8. Ref: https://developer.wordpress.org/themes/basics/template-hierarchy/ A web server converts/renders PHP files to a static HTML page which is sent to the browser along with any corresponding CSS and other asset files such as images. Static HTML pages rendered from PHP files cannot interact with the user in the browser no matter how much they wiggle, move or click their mouse pointer at things on the page.
  • 9. Ref: https://developer.wordpress.org/themes/basics/template-hierarchy/ JavaScript runs in the browser and detects “events” such as window resize, mouse overs/movement/clicks, field selections/changes/input etc. JavaScript functions are bound to browser events allowing the HTML and CSS of the static page to now be changed dynamically in response to that event.
  • 10. Most important template file. Your theme must have an index.php This is the main blog article archive/page and top of the hierarchy (last to render) If there are no other php template files, index.php will be used to render the current web page.
  • 12. 2nd most important theme file. Your theme must have a style.css This file contains the theme name, version, description and license type that is displayed on the Appearance > Themes dashboard panel.
  • 13. Other primary templates are: • archive.php The archive template is used when visitors request posts by category, author, or date. • single.php The single post template is used when a visitor requests a single post. • page.php The page template is used when visitors request individual pages, which are a built-in template.
  • 14. Other primary templates are: • singular.php The singular template is used for posts when single.php is not found, or for pages when page.php are not found. • home.php The home page template is the front page by default. If you do not set WordPress to use a static front page, this template is used to show latest posts. • front-page.php The front page template is always used as the site front page if it exists, regardless of what settings on Admin > Settings > Reading.
  • 15. Other primary templates are: • comments.php The comments template. • 404.php The 404 template is used when WordPress cannot find a post, page, or other content that matches the visitor’s request. • search.php The search results template is used to display a visitor’s search results.
  • 16. Needs to be in the root directory of your theme. /wp-content/themes/<unique_theme_name>/style.css WordPress uses the header comment section of a style.css to display information about the theme in the Appearance > Themes dashboard panel.
  • 17. These header comments in style.css are required. There are more you can use. /* Theme Name: Twenty Sixteen Author: the WordPress Team Description: Twenty Sixteen is a modernised take on an ever- popular WordPress layout Version: 1.3 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: twentysixteen */ Ref: https://developer.wordpress.org/themes/basics/main-stylesheet-style-css/
  • 19. There is no official required theme folder structure. Here’s an example based on Twenty Sixteen. Primary template files are located in the root of your theme folder. Assets are in a separate sub folder. assets (dir) - css (dir) - images (dir) - js (dir) template-parts (dir) - footer (dir) - header (dir) - navigation (dir) - page (dir) - post (dir) 404.php archive.php footer.php front-page.php functions.php header.php index.php page.php README.txt rtl.css screenshot.png single.php style.css
  • 20. Template tags are used within themes to retrieve content from your database. They help you to avoid hard coding content into template files. A template tag is broken up into three parts: • A PHP code tag • A WordPress function • Optional parameters Ref: https://developer.wordpress.org/themes/basics/template-tags/
  • 21. Printing the header.php file using get_header(): <?php get_header(); ?> Printing the blog site title (Settings > General): <?php bloginfo(‘name’); ?> Other template tags: the_content() the_excerpt() next_post() previous_post()
  • 22. The Loop is the default mechanism WordPress uses for outputting posts through a theme’s template files. The Loop extracts the data for each post from the WordPress database and inserts the appropriate information in place of each template tag. Any HTML or PHP code in The Loop will be processed for each post. Ref: https://developer.wordpress.org/themes/basics/the-loop/
  • 23. if ( have_posts() ) : while ( have_posts() ) : the_post(); the_content(); endwhile; else : _e( 'Sorry, no posts matched your criteria.', 'textdomain' ); endif;
  • 24. The functions.php file is where you add unique features to your WordPress theme. It can be used to hook into the core functions of WordPress to make your theme more modular, extensible, and functional. Each theme has its own functions file, but only code in the active theme’s functions.php is actually run. If your theme already has a functions file, you can add code to it. Ref: https://developer.wordpress.org/themes/basics/theme-functions/
  • 25. if ( ! function_exists( 'myfirsttheme_setup' ) ) : /** * Sets up theme defaults and registers support for various WordPress features. */ function myfirsttheme_setup() { /** * Make theme available for translation. * Translations can be placed in the /languages/ directory. */ load_theme_textdomain( 'myfirsttheme', get_template_directory() . '/languages' ); } endif; // myfirsttheme_setup add_action( 'after_setup_theme', 'myfirsttheme_setup' ); Ref: https://developer.wordpress.org/themes/basics/theme-functions/
  • 26. You may want to create additional style sheet or JavaScript files to enhance your theme. The proper way to add scripts and styles to your theme is to enqueue them in the functions.php file. You do not add them manually to the header.php file as you would with an HTML page. Ref: https://developer.wordpress.org/themes/basics/including-css-javascript
  • 27. Function: wp_enqueue_style( $handle, $src, $deps, $ver, $media ); Parameters: • $handle is simply the name of the stylesheet. • $src is where it is located. The rest of the parameters are optional. • $deps refers to whether or not this stylesheet is dependent on another stylesheet. If this is set, this stylesheet will not be loaded unless its dependent stylesheet is loaded first. • $ver sets the version number. • $media specify type of media to load, such as ‘all’, ‘screen’, or ‘print’ Basic function use: wp_enqueue_style( 'style', get_stylesheet_uri() );
  • 28. Function: wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); Parameters: • $handle is simply the name of the script. • $src is where it is located. The rest of the parameters are optional. • $deps is an array that can handle any script that your new script depends on, such as jQuery. • $ver sets the version number. • $in_footer is a boolean parameter (true/false) that allows you to place your scripts in the footer of your HTML document rather then in the header Basic function use: wp_enqueue_script( script', get_template_directory_uri() );
  • 29. Styles and scripts are usually loaded on an action hook. E.g. /** * Proper way to enqueue scripts and styles */ function wpdocs_theme_name_scripts() { wp_enqueue_style( 'style-name', get_stylesheet_uri() ); wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
  • 30. Can be used in your template files to alter the display of content depending on the conditions that the current page matches. Display a different greeting for logged in/out users. if ( is_user_logged_in() ): echo 'Welcome, registered user!'; else: echo 'Welcome, visitor!'; endif; Ref: https://developer.wordpress.org/themes/basics/conditional-tags/
  • 31. Developing your theme, so it can easily be translated into other languages. To make a string translatable you have to wrap the original strings in a set of special functions that use your uniquely defined text domain. The text domain is a unique identifier, which makes sure WordPress can distinguish between all loaded translations. Ref: https://developer.wordpress.org/themes/functionality/internationalization/
  • 32. Rather than use English only output: echo 'Your city is $city.‘ Run it through the __() PHP gettext library for translation using the my-theme text domain: printf( __( 'Your city is %s.', 'my-theme' ), $city );
  • 33. A child theme allows you to change small aspects of your site’s appearance yet still preserve your theme’s look and functionality. Parent Theme A parent theme is a complete theme which includes all of the required WordPress template files and assets for the theme to work Ref: https://developer.wordpress.org/themes/advanced-topics/child-themes/
  • 34. Inherits the look and feel of the parent theme and all of its functions, but can be used to make modifications to any part of the theme. In this way, customizations are kept separate from the parent theme’s files. Using a child theme lets you upgrade/override the parent theme without affecting the customizations you’ve made to your site.
  • 35. Example: You may have bought a premium theme and created a child theme to tweak a few styles and pages. A major bug is found in the parent theme and fixed by the author. An update is available in the dashboard.
  • 36. Example continued… You update the parent successfully. Your changes in the child theme are not deleted and still override the newly updated parent theme. Had you changed the parent theme, your changes would have been lost with the new update.
  • 37. WordPress theme frameworks are intended to be used as parent themes to aid the development of a child theme. They contain all the basic structures and functionalities you would need to create a theme but lack the styling and completeness you would expect to find in a working theme for a website. Ref: https://codex.wordpress.org/Theme_Frameworks
  • 38. As a parent theme, the framework can be updated to add new features and fix issues. Customizations to the child theme, hence the actual website, remain separate and unchanged, inheriting the new features and receiving framework issue fixes. Developers like using frameworks for consistency across sites and access to a larger community of other skilled framework developers.
  • 39. A popular commercial framework is Genesis. Other frameworks include: • Headway (drag & drop) • Divi (drag & drop) • Themify • Beans • Unyson
  • 40. Consider theme security as you add functionality. • Don’t trust any data. Validate all input from users, 3rd party APIs and the database and sanitize (escape) data before use or output. • Use WordPress API functions first. Core WordPress functions provide functionality of validating and sanitizing data. • Keep your theme up to date. Technology evolves and bugs get found and fixed over time. Ref: https://developer.wordpress.org/themes/theme-security/
  • 41. A theme must meet certain requirements to be included in the WordPress.org theme repository. Adhering to these requirements is best practice for theme development even if you don’t intend to submit to the repository at WordPress.org Accessibility, Code Quality, Use of Core Features, Documentation, Language, Licensing, etc… Ref: https://make.wordpress.org/themes/handbook/review/required/
  • 42. Themes are reviewed by the Theme Review Team. Before uploading, your theme must adhere to • Theme Review Guidelines • Testing With Sample Data • Theme Check Plugin Read the actual review process the team uses. Ref: https://developer.wordpress.org/themes/release/submitting-your-theme-to-wordpress-org/
  • 43. The most important thing about designing and developing a theme is that you have fun doing it!
  • 44. [Cover/Background] marktimemedia.com [9] marktimemedia.com [10] marktimemedia.com [43] imgur.com [Back Cover] zeropointdevelopment.com
  • 45.  20+ years in IT: Dev & SysOps  WordPress Developer since 2008  Plugins, APIs, Security & Systems Integrations  Organiser WPSyd & WordCamp Sydney zeropointdevelopment.com @DeveloperWil ♥ Pizza & Craft Beer