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

What's hot

ARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversGilbert Guerrero
 
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
Scott DeLoach
 
Joomla! Day Los Angeles 2011 WebMatrix
Joomla! Day Los Angeles 2011 WebMatrixJoomla! Day Los Angeles 2011 WebMatrix
Joomla! Day Los Angeles 2011 WebMatrixAlice Pang
 
Hello, Canvas.
Hello, Canvas.Hello, Canvas.
Hello, Canvas.
Seth McLaughlin
 
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStartBest Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Scott DeLoach
 
J day la 2011 webmatrix
J day la 2011 webmatrixJ day la 2011 webmatrix
J day la 2011 webmatrixAlice Pang
 
Yuihacku iitd-sumana
Yuihacku iitd-sumanaYuihacku iitd-sumana
Yuihacku iitd-sumana
Sumana Hariharan
 
Jackie's porfolio edited
Jackie's porfolio editedJackie's porfolio edited
Jackie's porfolio edited
Jacquiline Tabelin
 
Admin footer
Admin footerAdmin footer
Railsgirls: Where did my HTML and CSS go
Railsgirls: Where did my HTML and CSS goRailsgirls: Where did my HTML and CSS go
Railsgirls: Where did my HTML and CSS go
Brigitte Jellinek
 
Responsive Web Design tehnike u WordPress-u
Responsive Web Design tehnike u WordPress-uResponsive Web Design tehnike u WordPress-u
Responsive Web Design tehnike u WordPress-u
Igor Benić
 
Be nice to your designers
Be nice to your designersBe nice to your designers
Be nice to your designersPai-Cheng Tao
 
Element Styles and Positioning
Element Styles and PositioningElement Styles and Positioning
Element Styles and Positioning
alexisabril
 
Quickstrat fusionchart
Quickstrat fusionchartQuickstrat fusionchart
Quickstrat fusionchart
Deni Ywn
 
How To Start Building Your Own Website With Drupal by Mary Chris Casis
How To Start Building Your Own Website With Drupal by Mary Chris CasisHow To Start Building Your Own Website With Drupal by Mary Chris Casis
How To Start Building Your Own Website With Drupal by Mary Chris Casis
Promet Source
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
Matthew Beale
 
Jquery Cheatsheet
Jquery CheatsheetJquery Cheatsheet
Jquery Cheatsheet
Daniel Downs
 
Scaling Complexity in WordPress Enterprise Apps
Scaling Complexity in WordPress Enterprise AppsScaling Complexity in WordPress Enterprise Apps
Scaling Complexity in WordPress Enterprise Apps
Mike Schinkel
 

What's hot (20)

ARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: Rollovers
 
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
 
css navigation
css navigationcss navigation
css navigation
 
Joomla! Day Los Angeles 2011 WebMatrix
Joomla! Day Los Angeles 2011 WebMatrixJoomla! Day Los Angeles 2011 WebMatrix
Joomla! Day Los Angeles 2011 WebMatrix
 
Hello, Canvas.
Hello, Canvas.Hello, Canvas.
Hello, Canvas.
 
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStartBest Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
 
J day la 2011 webmatrix
J day la 2011 webmatrixJ day la 2011 webmatrix
J day la 2011 webmatrix
 
Yuihacku iitd-sumana
Yuihacku iitd-sumanaYuihacku iitd-sumana
Yuihacku iitd-sumana
 
Jackie's porfolio edited
Jackie's porfolio editedJackie's porfolio edited
Jackie's porfolio edited
 
Admin footer
Admin footerAdmin footer
Admin footer
 
Railsgirls: Where did my HTML and CSS go
Railsgirls: Where did my HTML and CSS goRailsgirls: Where did my HTML and CSS go
Railsgirls: Where did my HTML and CSS go
 
Responsive Web Design tehnike u WordPress-u
Responsive Web Design tehnike u WordPress-uResponsive Web Design tehnike u WordPress-u
Responsive Web Design tehnike u WordPress-u
 
Be nice to your designers
Be nice to your designersBe nice to your designers
Be nice to your designers
 
Element Styles and Positioning
Element Styles and PositioningElement Styles and Positioning
Element Styles and Positioning
 
Quickstrat fusionchart
Quickstrat fusionchartQuickstrat fusionchart
Quickstrat fusionchart
 
How To Start Building Your Own Website With Drupal by Mary Chris Casis
How To Start Building Your Own Website With Drupal by Mary Chris CasisHow To Start Building Your Own Website With Drupal by Mary Chris Casis
How To Start Building Your Own Website With Drupal by Mary Chris Casis
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
 
BBUI
BBUIBBUI
BBUI
 
Jquery Cheatsheet
Jquery CheatsheetJquery Cheatsheet
Jquery Cheatsheet
 
Scaling Complexity in WordPress Enterprise Apps
Scaling Complexity in WordPress Enterprise AppsScaling Complexity in WordPress Enterprise Apps
Scaling Complexity in WordPress Enterprise Apps
 

Similar to WordPress Theme Workshop: CSS/JS

How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress theme
Hardeep Asrani
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
Amanda Giles
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
Amanda Giles
 
WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4
David Bisset
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Erin M. Kidwell
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
Nile Flores
 
ViA Bootstrap 4
ViA Bootstrap 4ViA Bootstrap 4
ViA Bootstrap 4
imdurgesh
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
Chandra Prakash Thapa
 
Intermediate Web Design
Intermediate Web DesignIntermediate Web Design
Intermediate Web Design
mlincol2
 
WordPress Theme Workshop: Misc
WordPress Theme Workshop: MiscWordPress Theme Workshop: Misc
WordPress Theme Workshop: Misc
David Bisset
 
Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)
Kris Wallsmith
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
Paul Bearne
 
[SUTD GDSC] Intro to HTML and CSS
[SUTD GDSC] Intro to HTML and CSS[SUTD GDSC] Intro to HTML and CSS
[SUTD GDSC] Intro to HTML and CSS
BeckhamWee
 
Theming Wordpress with Adobe
Theming Wordpress with AdobeTheming Wordpress with Adobe
Theming Wordpress with Adobe
Grace Solivan
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentation
alledia
 
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
SURYANARAYANBISWAL1
 
Creating WordPress Theme Faster, Smarter & Without Swearing
Creating WordPress Theme Faster, Smarter & Without SwearingCreating WordPress Theme Faster, Smarter & Without Swearing
Creating WordPress Theme Faster, Smarter & Without Swearingmartinwolak
 
Enjoy the vue.js
Enjoy the vue.jsEnjoy the vue.js
Enjoy the vue.js
TechExeter
 
You're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp AtlantaYou're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp Atlanta
Chris Scott
 
Introduction to WordPress & Theme Development
Introduction to WordPress & Theme DevelopmentIntroduction to WordPress & Theme Development
Introduction to WordPress & Theme Development
Najmul Haque
 

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

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

More from David Bisset

WordPress Theme Workshop: Part 0
WordPress Theme Workshop: Part 0WordPress Theme Workshop: Part 0
WordPress Theme Workshop: Part 0
David Bisset
 
WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 1WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 1
David Bisset
 
WordPress Theme Workshop: Part 2
WordPress Theme Workshop: Part 2WordPress Theme Workshop: Part 2
WordPress Theme Workshop: Part 2
David Bisset
 
WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3
David Bisset
 
WordPress Theme Workshop: Customizer
WordPress Theme Workshop: CustomizerWordPress Theme Workshop: Customizer
WordPress Theme Workshop: Customizer
David Bisset
 
WordPress Theme Workshop: Internationalization
WordPress Theme Workshop: InternationalizationWordPress Theme Workshop: Internationalization
WordPress Theme Workshop: Internationalization
David Bisset
 
WordPress Theme Workshop: Widgets
WordPress Theme Workshop: WidgetsWordPress Theme Workshop: Widgets
WordPress Theme Workshop: Widgets
David Bisset
 
WordPress Theme Workshop: Menus
WordPress Theme Workshop: MenusWordPress Theme Workshop: Menus
WordPress Theme Workshop: Menus
David Bisset
 
WordPress Theme Workshop: Sidebars
WordPress Theme Workshop: SidebarsWordPress Theme Workshop: Sidebars
WordPress Theme Workshop: Sidebars
David Bisset
 
WordPress Theme Workshop: Theme Setup
WordPress Theme Workshop: Theme SetupWordPress Theme Workshop: Theme Setup
WordPress Theme Workshop: Theme Setup
David Bisset
 
BuddyPress & Higher Education
BuddyPress & Higher EducationBuddyPress & Higher Education
BuddyPress & Higher Education
David Bisset
 
WordPress Meetup (Davie, FL) - Top 9 April 2016
WordPress Meetup (Davie, FL) - Top 9 April 2016WordPress Meetup (Davie, FL) - Top 9 April 2016
WordPress Meetup (Davie, FL) - Top 9 April 2016
David Bisset
 
WordCamp Tampa 2015
WordCamp Tampa 2015WordCamp Tampa 2015
WordCamp Tampa 2015David Bisset
 
WPSessions - Thinking Outside The Box With BuddyPress
WPSessions - Thinking Outside The Box With BuddyPressWPSessions - Thinking Outside The Box With BuddyPress
WPSessions - Thinking Outside The Box With BuddyPressDavid Bisset
 
Building Next Generation Applications With BuddyPress
Building Next Generation Applications With BuddyPressBuilding Next Generation Applications With BuddyPress
Building Next Generation Applications With BuddyPress
David Bisset
 
Be a Part of Something Bigger: Get Involved with WordPress
Be a Part of Something Bigger: Get Involved with WordPressBe a Part of Something Bigger: Get Involved with WordPress
Be a Part of Something Bigger: Get Involved with WordPress
David Bisset
 
WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015
David Bisset
 
WordPress Miami Meetup: Top 9 (August 2015)
WordPress Miami Meetup: Top 9 (August 2015)WordPress Miami Meetup: Top 9 (August 2015)
WordPress Miami Meetup: Top 9 (August 2015)
David Bisset
 

More from David Bisset (20)

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

Recently uploaded

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 

Recently uploaded (20)

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 

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' );