SlideShare a Scribd company logo
1 of 11
Download to read offline
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
 
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, ClickStartScott DeLoach
 
J day la 2011 webmatrix
J day la 2011 webmatrixJ day la 2011 webmatrix
J day la 2011 webmatrixAlice Pang
 
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 goBrigitte 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-uIgor 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 Positioningalexisabril
 
Quickstrat fusionchart
Quickstrat fusionchartQuickstrat fusionchart
Quickstrat fusionchartDeni 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 CasisPromet Source
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.jsMatthew Beale
 
Scaling Complexity in WordPress Enterprise Apps
Scaling Complexity in WordPress Enterprise AppsScaling Complexity in WordPress Enterprise Apps
Scaling Complexity in WordPress Enterprise AppsMike 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 themeHardeep Asrani
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme EnlightenmentAmanda Giles
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017Amanda Giles
 
WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4David 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 WordPressNile Flores
 
ViA Bootstrap 4
ViA Bootstrap 4ViA Bootstrap 4
ViA Bootstrap 4imdurgesh
 
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 NepalChandra Prakash Thapa
 
Intermediate Web Design
Intermediate Web DesignIntermediate Web Design
Intermediate Web Designmlincol2
 
WordPress Theme Workshop: Misc
WordPress Theme Workshop: MiscWordPress Theme Workshop: Misc
WordPress Theme Workshop: MiscDavid 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-1919Paul 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 CSSBeckhamWee
 
Theming Wordpress with Adobe
Theming Wordpress with AdobeTheming Wordpress with Adobe
Theming Wordpress with AdobeGrace Solivan
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentationalledia
 
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.jsTechExeter
 
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 AtlantaChris Scott
 
Introduction to WordPress & Theme Development
Introduction to WordPress & Theme DevelopmentIntroduction to WordPress & Theme Development
Introduction to WordPress & Theme DevelopmentNajmul 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 0David Bisset
 
WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 1WordPress Theme Workshop: Part 1
WordPress Theme Workshop: Part 1David Bisset
 
WordPress Theme Workshop: Part 2
WordPress Theme Workshop: Part 2WordPress Theme Workshop: Part 2
WordPress Theme Workshop: Part 2David Bisset
 
WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3David Bisset
 
WordPress Theme Workshop: Customizer
WordPress Theme Workshop: CustomizerWordPress Theme Workshop: Customizer
WordPress Theme Workshop: CustomizerDavid Bisset
 
WordPress Theme Workshop: Internationalization
WordPress Theme Workshop: InternationalizationWordPress Theme Workshop: Internationalization
WordPress Theme Workshop: InternationalizationDavid Bisset
 
WordPress Theme Workshop: Widgets
WordPress Theme Workshop: WidgetsWordPress Theme Workshop: Widgets
WordPress Theme Workshop: WidgetsDavid Bisset
 
WordPress Theme Workshop: Menus
WordPress Theme Workshop: MenusWordPress Theme Workshop: Menus
WordPress Theme Workshop: MenusDavid Bisset
 
WordPress Theme Workshop: Sidebars
WordPress Theme Workshop: SidebarsWordPress Theme Workshop: Sidebars
WordPress Theme Workshop: SidebarsDavid Bisset
 
WordPress Theme Workshop: Theme Setup
WordPress Theme Workshop: Theme SetupWordPress Theme Workshop: Theme Setup
WordPress Theme Workshop: Theme SetupDavid Bisset
 
BuddyPress & Higher Education
BuddyPress & Higher EducationBuddyPress & Higher Education
BuddyPress & Higher EducationDavid 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 2016David 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 BuddyPressDavid 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 WordPressDavid Bisset
 
WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015David 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

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

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