SlideShare a Scribd company logo
WordPress Theme
Workshop: CSS/JS
November 4th, 2017
David Bisset
davidbisset.com / @dimensionmedia
Including CSS and JS: The Wrong Way
<html>
<head>
<title>My WordPress Site</title>
<script src=“myScript.js”></script>
<link rel="stylesheet" type="text/css" href=“mystyle.css">
</html>
<body>
Including CSS and JS: The Wrong Way
<html>
<head>
<title>My WordPress Site</title>
<script src=“myScript.js”></script>
<link rel="stylesheet" type="text/css" href=“mystyle.css">
</html>
<body>
Including CSS and JS: The Wrong Way
<html>
<head>
<title>My WordPress Site</title>
<script src=“myScript.js”></script>
<link rel="stylesheet" type="text/css" href=“mystyle.css">
</html>
<body>
Including CSS and JS: The Right Way
<?php
/**
* Enqueue scripts and styles.This Can Be InYour Functions.PHP
*/
function load_my_scripts() {
wp_enqueue_style( 'testme-style', get_stylesheet_uri() );
/* SIMPLE */
wp_enqueue_script( ‘testme-custom-script', get_template_directory_uri() .‘/js/custom_sript.js’ );
/* MORE ADVANCED */
wp_enqueue_script( ‘testme-custom-script', get_template_directory_uri() .‘/js/custom_sript.js’,
array(‘jquery’), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts',‘load_my_scripts' );
Step One
AddYour CSS or JS file into your theme
Step Two: CSS
RegisterYour CSS File w/ wp_register_style()
wp_register_style(
'my-css-file', // handle name
get_template_directory_uri() .‘/css/custom.css’,
// the URL of the stylesheet
array( 'bootstrap-main' ), // an array of dependent styles
'1.2', // version number
'screen', // CSS media type
);
wp_register_style( $handle, $src, $deps, $ver, $media );
Step Three: CSS
After registering our style file, we need to "enqueue" it to
make it ready to load in our theme's <head> section.
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Step Three: CSS
Two different ways to use wp_enqueue_style():
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
// if we registered the style before:
wp_enqueue_style( 'my-bootstrap-extension' );
// if we didn't register it, we HAVE to set the $src parameter!
wp_enqueue_style(
'my-css-file', // handle name
get_template_directory_uri() .‘/css/custom.css’,
// the URL of the stylesheet
array( 'bootstrap-main' ), // an array of dependent styles
'1.2', // version number
'screen', // CSS media type
);
Step Four: Use Actions
We can't just use the wp_enqueue_style() function
anywhere in our theme – we need to use "actions".There
are three actions we can use for various purposes:
// load css into the website's front-end
function mytheme_enqueue_style() {
wp_enqueue_style( 'mytheme-style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_style' );
// load css into the admin pages
function mytheme_enqueue_options_style() {
wp_enqueue_style( 'mytheme-options-style', get_template_directory_uri() . '/css/admin.css' );
}
add_action( 'admin_enqueue_scripts', 'mytheme_enqueue_options_style' );
// load css into the login page
function mytheme_enqueue_login_style() {
wp_enqueue_style( 'mytheme-options-style', get_template_directory_uri() . '/css/login.css' );
}
add_action( 'login_enqueue_scripts', 'mytheme_enqueue_login_style' );
How to Properly Enqueue Scripts
in WordPress
Use these in functions.php: wp_register_script() and
wp_enqueue_script();
function wpb_adding_scripts() {
wp_register_script(‘testme-custom-script', get_template_directory_uri() .‘/js/
custom_sript.js’, array(‘jquery’), '20151215', true);
wp_enqueue_script('testme-custom-script');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );

More Related Content

PDF
CSS Workflow. Pre & Post
PPT
CMS 101 Drupal
PDF
Front End Tooling and Performance - Codeaholics HK 2015
PDF
Front End Development - Beyond Javascript (Robin Cannon)
PDF
CSS架構如何加速功能開發
DOCX
Karan.chanana|css-rules
PDF
Responsive WordPress workflow
PPTX
HTML Tour - Buenas prácticas en el desarrollo web
CSS Workflow. Pre & Post
CMS 101 Drupal
Front End Tooling and Performance - Codeaholics HK 2015
Front End Development - Beyond Javascript (Robin Cannon)
CSS架構如何加速功能開發
Karan.chanana|css-rules
Responsive WordPress workflow
HTML Tour - Buenas prácticas en el desarrollo web

What's hot (20)

KEY
ARTDM 170 Week 3: Rollovers
PDF
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
PDF
css navigation
PPTX
Joomla! Day Los Angeles 2011 WebMatrix
PDF
Hello, Canvas.
PDF
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
PPTX
J day la 2011 webmatrix
PPT
Yuihacku iitd-sumana
TXT
Jackie's porfolio edited
DOC
PDF
Railsgirls: Where did my HTML and CSS go
PDF
Responsive Web Design tehnike u WordPress-u
PDF
Be nice to your designers
PPTX
Element Styles and Positioning
PPTX
Quickstrat fusionchart
PPTX
How To Start Building Your Own Website With Drupal by Mary Chris Casis
PDF
Parse Apps with Ember.js
PPTX
PDF
Jquery Cheatsheet
PDF
Scaling Complexity in WordPress Enterprise Apps
ARTDM 170 Week 3: Rollovers
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
css navigation
Joomla! Day Los Angeles 2011 WebMatrix
Hello, Canvas.
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
J day la 2011 webmatrix
Yuihacku iitd-sumana
Jackie's porfolio edited
Railsgirls: Where did my HTML and CSS go
Responsive Web Design tehnike u WordPress-u
Be nice to your designers
Element Styles and Positioning
Quickstrat fusionchart
How To Start Building Your Own Website With Drupal by Mary Chris Casis
Parse Apps with Ember.js
Jquery Cheatsheet
Scaling Complexity in WordPress Enterprise Apps
Ad

Similar to WordPress Theme Workshop: CSS/JS (20)

PDF
How to make a WordPress theme
PPTX
The Way to Theme Enlightenment
PPTX
The Way to Theme Enlightenment 2017
PDF
WordPress Theme Workshop: Part 4
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
PPTX
PSD to WordPress
PDF
ViA Bootstrap 4
PPTX
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
PPTX
Intermediate Web Design
PDF
WordPress Theme Workshop: Misc
PDF
Assetic (Symfony Live Paris)
PPTX
Childthemes ottawa-word camp-1919
PPTX
[SUTD GDSC] Intro to HTML and CSS
PDF
Theming Wordpress with Adobe
PPT
Joomla Beginner Template Presentation
PPTX
INTRODUCTIONS OF CSS
PDF
Creating WordPress Theme Faster, Smarter & Without Swearing
PDF
Enjoy the vue.js
PDF
You're Doing it Wrong - WordCamp Atlanta
PPT
Introduction to WordPress & Theme Development
How to make a WordPress theme
The Way to Theme Enlightenment
The Way to Theme Enlightenment 2017
WordPress Theme Workshop: Part 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
PSD to WordPress
ViA Bootstrap 4
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
Intermediate Web Design
WordPress Theme Workshop: Misc
Assetic (Symfony Live Paris)
Childthemes ottawa-word camp-1919
[SUTD GDSC] Intro to HTML and CSS
Theming Wordpress with Adobe
Joomla Beginner Template Presentation
INTRODUCTIONS OF CSS
Creating WordPress Theme Faster, Smarter & Without Swearing
Enjoy the vue.js
You're Doing it Wrong - WordCamp Atlanta
Introduction to WordPress & Theme Development
Ad

More from David Bisset (20)

PDF
WordPress Theme Workshop: Part 0
PDF
WordPress Theme Workshop: Part 1
PDF
WordPress Theme Workshop: Part 2
PDF
WordPress Theme Workshop: Part 3
PDF
WordPress Theme Workshop: Customizer
PDF
WordPress Theme Workshop: Internationalization
PDF
WordPress Theme Workshop: Widgets
PDF
WordPress Theme Workshop: Menus
PDF
WordPress Theme Workshop: Sidebars
PDF
WordPress Theme Workshop: Theme Setup
PPTX
BuddyPress & Higher Education
PDF
WordPress Meetup (Davie, FL) - Top 9 April 2016
PDF
WordCamp Tampa 2015
PDF
BuddyPress v4
PDF
WPSessions - Thinking Outside The Box With BuddyPress
PDF
SunShine PHP
PDF
Building Next Generation Applications With BuddyPress
PDF
Be a Part of Something Bigger: Get Involved with WordPress
PDF
WordPress Meetup - Top 9 September 2015
PDF
WordPress Miami Meetup: Top 9 (August 2015)
WordPress Theme Workshop: Part 0
WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 2
WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Customizer
WordPress Theme Workshop: Internationalization
WordPress Theme Workshop: Widgets
WordPress Theme Workshop: Menus
WordPress Theme Workshop: Sidebars
WordPress Theme Workshop: Theme Setup
BuddyPress & Higher Education
WordPress Meetup (Davie, FL) - Top 9 April 2016
WordCamp Tampa 2015
BuddyPress v4
WPSessions - Thinking Outside The Box With BuddyPress
SunShine PHP
Building Next Generation Applications With BuddyPress
Be a Part of Something Bigger: Get Involved with WordPress
WordPress Meetup - Top 9 September 2015
WordPress Miami Meetup: Top 9 (August 2015)

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Empathic Computing: Creating Shared Understanding
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Understanding_Digital_Forensics_Presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
The AUB Centre for AI in Media Proposal.docx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Review of recent advances in non-invasive hemoglobin estimation
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation_ Review paper, used for researhc scholars
Empathic Computing: Creating Shared Understanding
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Agricultural_Statistics_at_a_Glance_2022_0.pdf

WordPress Theme Workshop: CSS/JS

  • 1. WordPress Theme Workshop: CSS/JS November 4th, 2017 David Bisset davidbisset.com / @dimensionmedia
  • 2. Including CSS and JS: The Wrong Way <html> <head> <title>My WordPress Site</title> <script src=“myScript.js”></script> <link rel="stylesheet" type="text/css" href=“mystyle.css"> </html> <body>
  • 3. Including CSS and JS: The Wrong Way <html> <head> <title>My WordPress Site</title> <script src=“myScript.js”></script> <link rel="stylesheet" type="text/css" href=“mystyle.css"> </html> <body>
  • 4. Including CSS and JS: The Wrong Way <html> <head> <title>My WordPress Site</title> <script src=“myScript.js”></script> <link rel="stylesheet" type="text/css" href=“mystyle.css"> </html> <body>
  • 5. Including CSS and JS: The Right Way <?php /** * Enqueue scripts and styles.This Can Be InYour Functions.PHP */ function load_my_scripts() { wp_enqueue_style( 'testme-style', get_stylesheet_uri() ); /* SIMPLE */ wp_enqueue_script( ‘testme-custom-script', get_template_directory_uri() .‘/js/custom_sript.js’ ); /* MORE ADVANCED */ wp_enqueue_script( ‘testme-custom-script', get_template_directory_uri() .‘/js/custom_sript.js’, array(‘jquery’), '20151215', true ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } add_action( 'wp_enqueue_scripts',‘load_my_scripts' );
  • 6. Step One AddYour CSS or JS file into your theme
  • 7. Step Two: CSS RegisterYour CSS File w/ wp_register_style() wp_register_style( 'my-css-file', // handle name get_template_directory_uri() .‘/css/custom.css’, // the URL of the stylesheet array( 'bootstrap-main' ), // an array of dependent styles '1.2', // version number 'screen', // CSS media type ); wp_register_style( $handle, $src, $deps, $ver, $media );
  • 8. Step Three: CSS After registering our style file, we need to "enqueue" it to make it ready to load in our theme's <head> section. wp_enqueue_style( $handle, $src, $deps, $ver, $media );
  • 9. Step Three: CSS Two different ways to use wp_enqueue_style(): wp_enqueue_style( $handle, $src, $deps, $ver, $media ); // if we registered the style before: wp_enqueue_style( 'my-bootstrap-extension' ); // if we didn't register it, we HAVE to set the $src parameter! wp_enqueue_style( 'my-css-file', // handle name get_template_directory_uri() .‘/css/custom.css’, // the URL of the stylesheet array( 'bootstrap-main' ), // an array of dependent styles '1.2', // version number 'screen', // CSS media type );
  • 10. Step Four: Use Actions We can't just use the wp_enqueue_style() function anywhere in our theme – we need to use "actions".There are three actions we can use for various purposes: // load css into the website's front-end function mytheme_enqueue_style() { wp_enqueue_style( 'mytheme-style', get_stylesheet_uri() ); } add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_style' ); // load css into the admin pages function mytheme_enqueue_options_style() { wp_enqueue_style( 'mytheme-options-style', get_template_directory_uri() . '/css/admin.css' ); } add_action( 'admin_enqueue_scripts', 'mytheme_enqueue_options_style' ); // load css into the login page function mytheme_enqueue_login_style() { wp_enqueue_style( 'mytheme-options-style', get_template_directory_uri() . '/css/login.css' ); } add_action( 'login_enqueue_scripts', 'mytheme_enqueue_login_style' );
  • 11. How to Properly Enqueue Scripts in WordPress Use these in functions.php: wp_register_script() and wp_enqueue_script(); function wpb_adding_scripts() { wp_register_script(‘testme-custom-script', get_template_directory_uri() .‘/js/ custom_sript.js’, array(‘jquery’), '20151215', true); wp_enqueue_script('testme-custom-script'); } add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );