Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Levelling up your WordPress development workflow

Levelling up your WordPress development workflow

A talk at WordCamp Toronto 2014 on making your WordPress theme development workflow more efficient and generally awesome!

Avatar for Dara Skolnick

Dara Skolnick

November 16, 2014
Tweet

Other Decks in Programming

Transcript

  1. A LITTLE ABOUT ME. I... live in Toronto work as

    web designer & front end developer have been developing WP themes for 9 years run my own small business lead Ladies Learning Code workshops & mentor at HackerYou am a first time WordCamp speaker!
  2. THIS TALK IS AIMED AT: WORDPRESS THEME DEVELOPERS WHO CREATE

    CUSTOM (PARENT) THEMES Suggestions can apply to either solo devs or teams.
  3. 1. YOU CAN AUTOMATE LOTS OF NON-FUN TASKS WHO LOVES

    COMPRESSING IMAGES, LINTING CODE, AND CREATING SPRITES? ANYONE?
  4. WORDPRESS DEV IS GREAT, OF COURSE... BUT HAVING THE TIME

    TO PURSUE OTHER THINGS IN LIFE IS ALSO PRETTY GREAT.
  5. FIRST DISCLAIMER THERE'S NO RIGHT WAY TO DO FRONT- END

    DEVELOPMENT — THIS IS JUST ONE WAY.
  6. WHY DEVELOP LOCALLY? No White Screen of Death™ on a

    client's live site Local sites load more quickly No embarrassment if when you eff things up Allows you to use version control You're using version control, right? Right? You can use task runners, CSS preprocessors, etc.
  7. MY LOCAL DEV PROCESS: 1. Develop the entire website locally

    2. Along the way, commit changes to git and push to Bitbucket 3. Copy local site to staging server 4. Copy staging site to client's server 5. If when changes are needed after initial development, make them on the local copy and push them to staging, and then live.
  8. MY LOCAL DEV PROCESS: At no point am I ever

    making changes directly to the live site. When you make all changes on your local copy first, you don't have to keep track of which codebase is the latest/correct version.
  9. WHAT MAMP DOES the "AMP" in MAMP/XAMPP/AMPPS stands for Apache,

    MySQL and PHP MySQL and PHP are required to run WP and Apache is highly recommended. Replicates setup of common web hosts on your computer Free MAMP gives you a local server located at http://localhost:8888 MAMP Pro lets you assign custom domain names to each local site (e.g. http://sitename.dev)
  10. SETTING UP YOUR FIRST LOCAL WORDPRESS SITE Installing WordPress with

    MAMP is as easy as... 1. Downloading WordPress and putting it in the folder that MAMP is watching 2. Setting up a new database in phpMyAdmin (also conveniently bundled with MAMP) 3. Editing wp-config.php to point at the database you just created 4. Congrats, friend! You now have a WordPress site running on your computer. For more detailed instructions, . CSS Tricks has a great screencast on this very topic
  11. TIME-WASTING WAYS TO START CUSTOM THEMES INCLUDE: Coding your theme

    from scratch Using an old theme of yours as a starter theme Using a default theme (like twentyfourteen) as a starter theme
  12. TIME WASTER #1: CODING YOUR THEME FROM SCRATCH Extremely repetitive

    Extremely time consuming Too much time on gruntwork and less on interesting work
  13. TIME WASTERS #2 + 3: USING A FINISHED THEME (YOURS

    OR WP'S) AS YOUR STARTER THEME Lots of time spent undoing old work (either yours or someone else's) Easy to make poor coding decisions based on laziness/what's already there Often end up with a lot of code bloat when stuff from the old theme that's irrelevant to yours sticks around
  14. THE BETTER WAY: USE A REAL STARTER THEME! A starter

    theme is a barebones theme that acts as a foundation for your custom theme.
  15. A GOOD STARTER THEME WILL ALSO TAKE CARE OF THINGS

    LIKE: Basic CSS for WordPress functionality you may forget about (say, image alignment classes and galleries) Functions for common theme tasks (like setting up menus and widget areas) Adhering to (Underscores is especially good with this for obvious reasons) WordPress coding standards
  16. STARTER THEMES FTW! THE TEDIOUS STUFF IS DONE FOR YOU

    AND THERE'S LITTLE TO NO STYLING TO UNDO.
  17. THE BEST STARTER THEME... IS YOUR OWN, PERSONALIZED STARTER THEME!

    No one knows your own coding style as well as you do.
  18. MY STARTER THEME IS BASED ON UNDERSCORES AND CONTAINS: A

    customized functions.php file with all my commonly used functions A starter script.js file with a few starter functions that most themes use All my Sass partials set up as I like them with some useful variables and mixins My latest gulpfile.js and package.json (more on that in a minute)
  19. 2 EXAMPLE FUNCTIONS IN MY CUSTOM STARTER THEME'S FUNCTIONS.PHP FILE

    / * * * M e d i a - s e t d e f a u l t i m a g e l i n k l o c a t i o n t o ' N o n e ' * / u p d a t e _ o p t i o n ( ' i m a g e _ d e f a u l t _ l i n k _ t y p e ' , ' n o n e ' ) ; / * * * A l w a y s S h o w K i t c h e n S i n k i n W Y S I W Y G E d i t o r * / f u n c t i o n u n h i d e _ k i t c h e n s i n k ( $ a r g s ) { $ a r g s [ ' w o r d p r e s s _ a d v _ h i d d e n ' ] = f a l s e ; r e t u r n $ a r g s ; } a d d _ f i l t e r ( ' t i n y _ m c e _ b e f o r e _ i n i t ' , ' u n h i d e _ k i t c h e n s i n k ' ) ;
  20. ANOTHER CUSTOM STARTER BONUS You can bake in more accessibility

    feature than you'll find in standard starters.
  21. WHERE DO I KEEP MY STARTER THEME? There's no better

    place to store your starter theme than or . GitHub Bitbucket
  22. NOW, STARTING A NEW WORDPRESS PROJECT IS AS EASY AS:

    1. Downloading WordPress and setting it up in MAMP/XAMPP/AMPPS/thing that contains 'AMP' 2. Cloning your starter theme (or a fork of it) into /wp- content/themes/ 3. Logging into your new site's dashboard and activating your starter theme 4. Git coding! Git it? Version control jokes are super cool.
  23. NEVER USED GIT BEFORE? NO WORRIES! I'll be talking more

    about it a little later and will give you some good starter resources.
  24. SOME OF MY FAVOURITE DEVELOPMENT TASKS INCLUDE: Remembering which browser

    prefixes to use in CSS Compressing my images Linting and minifying JS files Creating sprites Constantly refreshing my browser
  25. WHAT ARE GRUNT AND GULP? Built on $ R u

    n o n t h e c o m m a n d l i n e Use plugins to run tasks
  26. GULP SHOULD RUN IN YOUR THEME DIRECTORY, NOT IN THE

    ROOT DIRECTORY OF YOUR WP INSTALLATION.
  27. CSS TASKS g u l p . t a s

    k ( ' s a s s ' , f u n c t i o n ( ) { r e t u r n g u l p . s r c ( ' s t y l e / s t y l e . s c s s ' ) . p i p e ( s a s s ( ) ) . p i p e ( a u t o p r e f i x e r ( ' l a s t 2 v e r s i o n ' , ' s a f a r i 5 ' , ' i e 8 ' , ' i e 9 ' , ' o p e r a 1 2 . 1 ' , ' i o s . p i p e ( m i n i f y c s s ( ) ) . p i p e ( g u l p . d e s t ( ' ' ) ) } ) ;
  28. IN PLAIN ENGLISH Gulp takes our Sass file... Turns it

    in to regular CSS Runs it through ... Minifies the CSS... And, finally, saves the CSS file. (All in a matter of milliseconds.) Autoprefixer
  29. CSS TASKS g u l p . t a s

    k ( ' s a s s ' , f u n c t i o n ( ) { r e t u r n g u l p . s r c ( ' s t y l e / s t y l e . s c s s ' ) . p i p e ( s a s s ( ) ) . p i p e ( a u t o p r e f i x e r ( ' l a s t 2 v e r s i o n ' , ' s a f a r i 5 ' , ' i e 8 ' , ' i e 9 ' , ' o p e r a 1 2 . 1 ' , ' i o s . p i p e ( m i n i f y c s s ( ) ) . p i p e ( g u l p . d e s t ( ' ' ) ) } ) ;
  30. TAKES THIS... . t h i n g - w

    i t h - c o l u m n s { c o l u m n - c o u n t : 3 ; c o l u m n - g a p : 4 0 p x ; } ...CHECKS CANIUSE.COM FOR BROWSER SUPPORT...
  31. AND GIVES YOU THIS. . t h i n g

    - w i t h - c o l u m n s { - w e b k i t - c o l u m n - c o u n t : 3 ; - m o z - c o l u m n - c o u n t : 3 ; c o l u m n - c o u n t : 3 ; - w e b k i t - c o l u m n - g a p : 4 0 p x ; - m o z - c o l u m n - g a p : 4 0 p x ; c o l u m n - g a p : 4 0 p x } :D
  32. HOW TO RUN GULP TASKS Type g u l p

    [ t a s k n a m e ] in your Terminal window.
  33. JAVASCRIPT LINTING g u l p . t a s

    k ( ' l i n t ' , f u n c t i o n ( ) { r e t u r n g u l p . s r c ( ' j s / s c r i p t . j s ' ) . p i p e ( j s h i n t ( ) ) . p i p e ( j s h i n t . r e p o r t e r ( ' d e f a u l t ' ) ) ; } ) ;
  34. JS CONCATENATION + MINIFICATION g u l p . t

    a s k ( ' s c r i p t s ' , f u n c t i o n ( ) { r e t u r n g u l p . s r c ( [ ' j s / p l u g i n s . j s ' , ' j s / s c r i p t . j s ' ] ) . p i p e ( c o n c a t ( ' s c r i p t . m i n . j s ' ) ) . p i p e ( u g l i f y ( ) ) . p i p e ( g u l p . d e s t ( ' j s ' ) ) ; } ) ;
  35. IMAGE COMPRESSION g u l p . t a s

    k ( ' i m a g e s ' , f u n c t i o n ( ) { v a r i m g S r c = ' i m g / s o u r c e / * ' ; v a r i m g D e s t = ' i m g ' ; r e t u r n g u l p . s r c ( i m g S r c ) . p i p e ( n e w e r ( i m g D e s t ) ) . p i p e ( i m a g e m i n ( ) ) . p i p e ( g u l p . d e s t ( i m g D e s t ) ) ; } ) ;
  36. BUT I SAVED THE BEST TASK FOR LAST TYPING G

    U L P S A S S , G U L P L I N T , G U L P S C R I P T S , AND G U L P I M A G E S OVER AND OVER WOULD SURE GET ANNOYING, RIGHT?
  37. MY BFF, THE WATCH TASK g u l p .

    t a s k ( ' w a t c h ' , f u n c t i o n ( ) { / / L i s t e n o n p o r t 3 5 7 2 9 s e r v e r . l i s t e n ( 3 5 7 2 9 , f u n c t i o n ( e r r ) { i f ( e r r ) { r e t u r n c o n s o l e . l o g ( e r r ) } ; / / W a t c h . j s f i l e s g u l p . w a t c h ( ' j s / * . j s ' , [ ' l i n t ' , ' s c r i p t s ' ] ) ; / / W a t c h . s c s s f i l e s g u l p . w a t c h ( ' * * / * . s c s s ' , [ ' s a s s ' ] ) ; / / W a t c h i m a g e f i l e s g u l p . w a t c h ( ' i m g / s o u r c e / * ' , [ ' i m a g e s ' ] ) ; } ) ; } ) ;
  38. WATCHES FOR YOUR CHANGES... ...RUNS THE APPROPRIATE TASKS... ... AND

    USES LIVERELOAD TO AUTOMATICALLY REFRESH YOUR BROWSER.
  39. GULP RESOURCES Getting started with gulp An Introduction to Gulp.js

    Using Gulp for WordPress Theme Development WordPress theme development with Gulp, Bower, and Sass
  40. VARIABLES PLAIN OL' CSS . c o n t a

    i n e r { m a x - w i d t h : 9 8 0 p x ; } a { c o l o r : # b 4 c 4 3 d ; f o n t - f a m i l y : ' G o t h a m A ' , ' G o t h a m B ' , s a n s - s e r i f ; }
  41. VARIABLES SASS / / F o n t s $

    g o t h a m : ' G o t h a m A ' , ' G o t h a m B ' , s a n s - s e r i f ; / / G l o b a l i n f o r m a t i o n $ p a g e W i d t h : 9 8 0 p x ; $ f o n t S i z e : 1 6 p x ; / / C o l o u r s $ g r e e n : # b 4 c 4 3 d ; $ t e a l : # 7 3 c 6 b a ; $ b r o w n : # 5 6 3 0 1 6 ;
  42. VARIABLES SASS . c o n t a i n

    e r { m a x - w i d t h : $ p a g e W i d t h ; } a { c o l o r : $ g r e e n ; f o n t - f a m i l y : $ g o t h a m ; }
  43. NESTING PLAIN OL' CSS . m a i n -

    n a v i g a t i o n { d i s p l a y : b l o c k ; } . m a i n - n a v i g a t i o n u l { l i s t - s t y l e : n o n e ; } . m a i n - n a v i g a t i o n l i { f l o a t : l e f t ; } . m a i n - n a v i g a t i o n a { c o l o r : # b 4 c 4 3 d ; } . m a i n - n a v i g a t i o n a : h o v e r { c o l o r : # 7 3 c 6 b a ; }
  44. NESTING SASS . m a i n - n a

    v i g a t i o n { d i s p l a y : b l o c k ; u l { l i s t - s t y l e : n o n e ; } l i { f l o a t : l e f t ; } a { c o l o r : $ g r e e n ; & : h o v e r { c o l o r : $ t e a l ; } } }
  45. PARTIALS / * ! T h e m e N

    a m e : S u p e r A w e s o m e T h e m e T h e m e U R I : h t t p : / / f a k e y f a k e . f a k e A u t h o r : D a r a S k o l n i c k A u t h o r U R I : h t t p : / / d a r a s k o l n i c k . c o m D e s c r i p t i o n : T h e f a k e s t t h e m e i n a l l t h e l a n d * / @ i m p o r t " p a r t i a l s / r e s e t " ; @ i m p o r t " p a r t i a l s / v a r i a b l e s " ; @ i m p o r t " p a r t i a l s / g l o b a l " ; @ i m p o r t " p a r t i a l s / f o r m s " ; @ i m p o r t " p a r t i a l s / n a v " ; @ i m p o r t " p a r t i a l s / p a g e s " ; @ i m p o r t " p a r t i a l s / p o s t s " ; @ i m p o r t " p a r t i a l s / w i d g e t s " ;
  46. MATH PLAIN OL' CSS . s i d e b

    a r { w i d t h : 3 6 . 7 3 4 6 9 3 8 7 8 % ; / * 3 6 0 p x / 9 8 0 p x * / f o n t - s i z e : 1 . 3 1 2 5 e m ; / * 2 1 p x / 1 6 p x * / }
  47. MATH SASS . s i d e b a r

    { w i d t h : 3 6 0 p x / 9 8 0 p x * 1 0 0 % ; f o n t - s i z e : 2 1 p x / 1 6 p x * 1 e m ; }
  48. MATH SASS . s i d e b a r

    { w i d t h : 3 6 0 p x / $ p a g e W i d t h * 1 0 0 % ; f o n t - s i z e : 2 0 p x / $ f o n t S i z e * 1 e m ; }
  49. HEY! WHAT'S WRONG WITH FTP? SO GLAD YOU ASKED! Sooooo

    slow Easy to forget which files need updating Tempting to make changes directly on the server Therefore easy to get your local + remote copies out of sync
  50. DEPLOYING WITH GIT $ g i t a d d

    - A / / a d d s a l l y o u r c h a n g e d f i l e s $ g i t c o m m i t - m " A m e s s a g e d e s c r i b i n g t h e c h a n g e s y o u m a d e " $ g i t p u s h r e m o t e - n a m e m a s t e r / / p u s h e s y o u r f i l e s t o G i t H u b / B i t b u c k e t / y o u r s i t e Most projects of mine have three remotes: origin (Bitbucket), staging (my dev server) and live (client's server).
  51. THIS IS AWESOME BECAUSE: Really easy (once you're used to

    it) Very quick Never have to remember which files you changed
  52. A FEW OPTIONS 1. Choose a host with Git support

    built in (e.g. ) 2. If you're using a more average host, use a service like or that FTPs changed files for you when you push to Git 3. If your web host allows SSH access, set it up yourself via command line (e.g. , ) WP Engine Deploy Beanstalk Hostgator Bluehost
  53. WORDPRESS-SPECIFIC GIT RESOURCES Version Controlling WordPress A WordPress & Git

    Workflow WordPress Development and Deployment With MAMP, Git and Dropbox
  54. IF GUIS ARE MORE YOUR STYLE / (free, and can

    be used with non-GitHub remotes) ($, Mac only) GitHub for Mac GitHub for Windows Tower
  55. IF DEPLOYING WITH GIT SEEMS TOO COMPLEX FOR NOW... Consider

    storing your client projects in private repositories to start. Builds good habits and makes it easier to collaborate with other developers.
  56. FEELING OVERWHELMED? Don't worry about doing everything at once Even

    the smallest workflow tweaks will save time