Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
WordCamp Phoenix 2013: WordPress 301: JavaScript
Search
Natalie MacLees
January 18, 2013
Technology
2
530
WordCamp Phoenix 2013: WordPress 301: JavaScript
A talk introducing JavaScript in general and how to correctly use JavaScript in WordPress.
Natalie MacLees
January 18, 2013
Tweet
Share
More Decks by Natalie MacLees
See All by Natalie MacLees
Creating content for everyone
nataliemac
0
40
Making your website work for everyone: accessibility testing
nataliemac
1
51
The Tangled Web We're Weaving: The Future of WordPress Accessibility
nataliemac
0
51
Making the world a better place through web design
nataliemac
0
150
One Percent Better: How little changes add up
nataliemac
1
100
One percent better
nataliemac
2
68
How to make time for a side hustle
nataliemac
0
3.8k
Before You React
nataliemac
2
390
Bulletproof JavaScript for plugins and themes
nataliemac
2
260
Other Decks in Technology
See All in Technology
株式会社EventHub・エンジニア採用資料
eventhub
0
4.2k
Moved to https://speakerdeck.com/toshihue/presales-engineer-career-bridging-tech-biz-ja
toshihue
2
550
Developer Summit 2025 [14-D-1] Yuki Hattori
yuhattor
19
5.1k
インフラをつくるとはどういうことなのか、 あるいはPlatform Engineeringについて
nwiizo
5
2.1k
生成AIの利活用を加速させるための取り組み「prAIrie-dog」/ Shibuya_AI_1
visional_engineering_and_design
1
140
技術的負債解消の取り組みと専門チームのお話 #技術的負債_Findy
bengo4com
1
1.2k
日経電子版 x AIエージェントの可能性とAgentic RAGによって提案書生成を行う技術
masahiro_nishimi
1
290
TAMとre:Capセキュリティ編 〜拡張脅威検出デモを添えて〜
fujiihda
1
110
2.5Dモデルのすべて
yu4u
2
610
リーダブルテストコード 〜メンテナンスしやすい テストコードを作成する方法を考える〜 #DevSumi #DevSumiB / Readable test code
nihonbuson
11
5.8k
SA Night #2 FinatextのSA思想/SA Night #2 Finatext session
satoshiimai
1
100
飲食店予約台帳を支えるインタラクティブ UI 設計と実装
siropaca
6
1.4k
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
GitHub's CSS Performance
jonrohan
1030
460k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
240
Large-scale JavaScript Application Architecture
addyosmani
510
110k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
For a Future-Friendly Web
brad_frost
176
9.5k
Agile that works and the tools we love
rasmusluckow
328
21k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Documentation Writing (for coders)
carmenintech
67
4.6k
Transcript
WordPress 301: JavaScript Natalie MacLees
About Me • Purple Pen Productions founder + principal •
jQuery for Designers author • SoCal WP Users’ Group organizer • jQuery LA Users’ Group founder + organizer @nataliemac | nataliemac.com
What is JavaScript? http://www.flickr.com/photos/bijoubaby/4539701617/
Extend HTML & CSS http://www.flickr.com/photos/liquene/3329868155/
Learning JavaScript How do we get started?
The Ideal http://www.flickr.com/photos/simonov/476780331/ learn it all perfectly, and then use
it
erinaceous lamprophony depone finnimbrun floccinaucinihilipilification inaniloquent limerance mesonoxian mungo nihilarian
The Reality http://www.flickr.com/photos/scalino/6629580443/ haphazard, learn as you go
Copy http://www.flickr.com/photos/5tein/2347819459/ and learn
Best Practices Things to keep in mind
Progressive Enhancement http://www.flickr.com/photos/kassel1/3104649691/ & graceful degradation
Layers Start with one and add on
Backend http://www.flickr.com/photos/14550765@N02/2505010784/
Content http://www.flickr.com/photos/andrea_r/3973740643 html
Presentation http://www.flickr.com/photos/lynstar/3880196378/ css
Behavior http://www.flickr.com/photos/auxesis/2964133796/ javascript
JavaScript in WordPress
Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"
/> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="/wp-content/themes/twentytwelve/scripts/ my-script.js"></script> <?php wp_head(); ?> </head>
Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"
/> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="/wp-content/themes/twentytwelve/scripts/ my-script.js"></script> <?php wp_head(); ?> </head>
Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"
/> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="<?php bloginfo('template_directory'); ?>/ scripts/my-script.js"></script> <?php wp_head(); ?> </head>
Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"
/> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="<?php bloginfo('template_directory'); ?>/ scripts/my-script.js"></script> <?php wp_head(); ?> </head>
WP Helper Functions wp_register_script( $handle, $src, $deps, $ver, $in_footer );
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
Including JavaScript functions.php function prefix_load_scripts() { ! wp_register_script( 'my-script', get_template_directory_uri()
. '/scripts/my- script.js' ); ! wp_enqueue_script( 'my-script' ); } add_action( 'wp_enqueue_scripts', 'prefix_load_scripts' );
Using Included Libraries functions.php function prefix_load_scripts() { ! wp_register_script( 'my-script',
get_template_directory_uri() . '/scripts/my-script.js', array( 'jquery' ), '1.0', true ); ! wp_enqueue_script( 'my-script' ); } add_action( 'wp_enqueue_scripts', 'prefix_load_scripts' );
Superfish Dropdowns Let’s get our hands dirty, shall we?
Dropdown Menus css-only
Suckerfish Dropdowns alistapart.com http://www.alistapart.com/articles/dropdowns/
Suckerfish Dropdowns alistapart.com http://www.alistapart.com/articles/dropdowns/
Superfish Dropdowns adding jQuery magic http://users.tpg.com.au/j_birch/plugins/superfish/
Quick Start Guide easy as 1-2-3 http://users.tpg.com.au/j_birch/plugins/superfish/
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme I’m naming my child theme ‘superfish’
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme most important file!
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme blank functions.php to start
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme collect all of our javascript files together
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme blank javascript file where we’ll write our script
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme from the superfish download
superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a
Child Theme from the superfish download
style.css /* Theme Name: Superfish Theme URI: http://purplepen.com Description: Child
theme for the Twenty Twelve theme adding Superfish menus Author: Natalie MacLees Author URI: http://nataliemac.com Template: twentytwelve Version: 0.1.0 */ @import url("../twentytwelve/style.css");
style.css /* Theme Name: Superfish Theme URI: http://purplepen.com Description: Child
theme for the Twenty Twelve theme adding Superfish menus Author: Natalie MacLees Author URI: http://nataliemac.com Template: twentytwelve Version: 0.1.0 */ @import url("../twentytwelve/style.css");
functions.php function superfish_load_scripts() { wp_register_script( 'hoverintent', get_stylesheet_directory_uri() . '/scripts/ hoverIntent.js',
array( 'jquery' ), '1.0', true ); }
functions.php function superfish_load_scripts() { ... wp_register_script( 'superfish', get_stylesheet_directory_uri() . '/scripts/
superfish.js', array( 'jquery', 'hoverintent' ), '1.0', true ); wp_register_script( 'custom-script', get_stylesheet_directory_uri() . '/scripts/custom.js', array( 'jquery', 'hoverintent', 'superfish' ), '1.3', true ); }
functions.php function superfish_load_scripts() { ... wp_enqueue_script( 'custom-script' ); } add_action(
'wp_enqueue_scripts', 'superfish_load_scripts' );
custom.js jQuery(document).ready(function() { jQuery('.main-navigation ul.nav-menu,.main-navigation div.nav-menu > ul').superfish(); });
custom.js jQuery(document).ready(function() { jQuery('.main-navigation ul.nav-menu,.main-navigation div.nav-menu > ul').superfish(); });
style.css ... @media screen and (min-width: 600px) { .sf-js-enabled li
ul { display: block; } }
custom.js jQuery(document).ready(function() { jQuery('.main-navigation ul.nav-menu,.main-navigation div.nav-menu > ul').superfish({ animation: {
height: 'show' } }); });
Resources Keep on learning
jQuery for Designers by some author http://www.amazon.com/jQuery-Designers-Beginners-Natalie-MacLees/dp/1849516707
JavaScript & WordPress by avk from WordCamp Nepal https://speakerdeck.com/avk/javascript-and-wordpress
Codrops lots of awesome tutorials http://tympanus.net/codrops/category/tutorials/
Codeacademy free JavaScript lessons http://www.codecademy.com
Eloquent JavaScript free interactive JavaScript book http://eloquentjavascript.net/
CodePen experiment and learn http://codepen.io/
Questions? Ask!
Thank YOU Have fun playing with JavaScript! @nataliemac | nataliemac.com