Top Banner
LEVELLING UP YOUR WORDPRESS DEVELOPMENT WORKFLOW WITH @DARASKOLNICK
110

Levelling up your WordPress development workflow

Jul 15, 2015

Download

Technology

daraskolnick
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Levelling up your WordPress development workflow

LEVELLING UP YOURWORDPRESS DEVELOPMENT

WORKFLOWWITH @DARASKOLNICK

Page 2: Levelling up your WordPress development workflow

HI, I'M DARA.NICE TO MEET YOU!

I'm @daraskolnick basically everywhere on the Internet.

Page 3: Levelling up your WordPress development workflow

A LITTLE ABOUT ME.I...

live in Torontowork as web designer & front end developerhave been developing WP themes for 9 yearsrun my own small businesslead Ladies Learning Code workshops & mentor atHackerYouam a first time WordCamp speaker!

Page 4: Levelling up your WordPress development workflow

THIS TALK IS AIMED AT:WORDPRESS THEME DEVELOPERSWHO CREATE CUSTOM (PARENT)

THEMESSuggestions can apply to either solo devs or teams.

Page 5: Levelling up your WordPress development workflow

SO, WHY IS HAVING AGOOD WORKFLOWSO IMPORTANT?

Page 6: Levelling up your WordPress development workflow

1. YOU CAN AUTOMATE LOTSOF NON-FUN TASKS

WHO LOVES COMPRESSING IMAGES,LINTING CODE, AND CREATING

SPRITES?ANYONE?

Page 7: Levelling up your WordPress development workflow

2. A GOOD WORKFLOWSAVES YOU TIME.

Page 8: Levelling up your WordPress development workflow

TIME = $$

Page 9: Levelling up your WordPress development workflow

BUT MORE IMPORTANTLY...TIME = FREEDOM

Page 10: Levelling up your WordPress development workflow

WORDPRESS DEV IS GREAT,OF COURSE...

BUT HAVING THE TIME TO PURSUEOTHER THINGS IN LIFE IS ALSO PRETTY

GREAT.

Page 11: Levelling up your WordPress development workflow

3. YOU CAN APPLY THE BEST,SEXIEST FRONT-END DEVPRACTICES TO WORDPRESS

THEMING

Page 12: Levelling up your WordPress development workflow

IF YOU'VE EVER WONDERED...

 

Page 13: Levelling up your WordPress development workflow

IF YOU'VE EVER WONDERED...

THEN THIS TALK IS FOR YOU!

Page 14: Levelling up your WordPress development workflow

FIRST DISCLAIMERTHERE'S NO RIGHT WAY TO DO FRONT-END DEVELOPMENT — THIS IS JUST

ONE WAY.

Page 15: Levelling up your WordPress development workflow

DEVS HAVE A LOT OFOPINIONS/FEELS ABOUT THE "RIGHT"

WAY TO DO THINGS

Page 16: Levelling up your WordPress development workflow

DON'T BE INTIMIDATED BY NEEDING TOUSE THE "RIGHT" TOOLS — SEE WHAT

WORKS BEST FOR YOU.

Page 17: Levelling up your WordPress development workflow

SECOND DISCLAIMERMOST OF THE NOT-SO-GOOD DEVPRACTICES I'LL TALK ABOUT COMEFROM FIRST HAND EXPERIENCE.

Page 18: Levelling up your WordPress development workflow

WORKFLOWIMPROVEMENT #1DEVELOPING LOCALLY

Page 19: Levelling up your WordPress development workflow

WHY DEVELOP LOCALLY?No White Screen of Death™ on a client's live siteLocal sites load more quicklyNo embarrassment if when you eff things upAllows you to use version controlYou're using version control, right? Right?

You can use task runners, CSS preprocessors, etc.

Page 20: Levelling up your WordPress development workflow

IF YOU'RE STILL DOING THIS...

Page 21: Levelling up your WordPress development workflow

IF YOU'RE STILL DOING THIS...

WE NEED TO TALK.

Page 22: Levelling up your WordPress development workflow

MY LOCAL DEV PROCESS:1. Develop the entire website locally2. Along the way, commit changes to git and push to

Bitbucket3. Copy local site to staging server4. Copy staging site to client's server5. If when changes are needed after initial development,

make them on the local copy and push them to staging,and then live.

Page 23: Levelling up your WordPress development workflow

MY LOCAL DEV PROCESS:At no point am I ever making changes directly to thelive site.When you make all changes on your local copy first, youdon't have to keep track of which codebase is thelatest/correct version.

Page 24: Levelling up your WordPress development workflow

MY LOCAL DEVENVIRONMENT OF CHOICE:

(Mac + Windows)MAMP/MAMP Pro

Page 25: Levelling up your WordPress development workflow

OTHER SIMILAR OPTIONS: (Mac, Windows and Linux) (Mac, Windows, Linux)

XAMPPAMPPS

Page 26: Levelling up your WordPress development workflow

WHAT MAMP DOESthe "AMP" in MAMP/XAMPP/AMPPS stands for Apache,MySQL and PHPMySQL and PHP are required to run WP and Apache ishighly recommended.Replicates setup of common web hosts on your computerFree MAMP gives you a local server located athttp://localhost:8888MAMP Pro lets you assign custom domain names to eachlocal site (e.g. http://sitename.dev)

Page 27: Levelling up your WordPress development workflow

SETTING UP YOUR FIRSTLOCAL WORDPRESS SITEInstalling WordPress with MAMP is as easy as...

1. Downloading WordPress and putting it in the folder thatMAMP is watching

2. Setting up a new database in phpMyAdmin (alsoconveniently bundled with MAMP)

3. Editing wp-config.php to point at the database you justcreated

4. Congrats, friend! You now have a WordPress site runningon your computer.For more detailed instructions,

.CSS Tricks has a great

screencast on this very topic

Page 28: Levelling up your WordPress development workflow

WORKFLOWIMPROVEMENT #2

USING A STARTER THEME

Page 29: Levelling up your WordPress development workflow

TIME-WASTING WAYS TOSTART CUSTOM THEMES

INCLUDE:Coding your theme from scratchUsing an old theme of yours as a starter themeUsing a default theme (like twentyfourteen) as a startertheme

Page 30: Levelling up your WordPress development workflow

TIME WASTER #1:CODING YOUR THEME FROM SCRATCH

Extremely repetitiveExtremely time consumingToo much time on gruntwork and less on interesting work

Page 31: Levelling up your WordPress development workflow

TIME WASTERS #2 + 3:USING A FINISHED THEME (YOURS ORWP'S) AS YOUR STARTER THEME

Lots of time spent undoing old work (either yours orsomeone else's)Easy to make poor coding decisions based onlaziness/what's already thereOften end up with a lot of code bloat when stuff from theold theme that's irrelevant to yours sticks around

Page 32: Levelling up your WordPress development workflow

THE BETTER WAY:USE A REAL STARTER THEME!

A starter theme is a barebones theme that acts as afoundation for your custom theme.

Page 33: Levelling up your WordPress development workflow

A FEW POPULAR STARTER THEMES (made by Automattic)Underscores

RootsBones

Page 34: Levelling up your WordPress development workflow

UNDERSCORES STARTS OFF LIKE THIS:

Page 35: Levelling up your WordPress development workflow

BASIC FILE STRUCTURE IS TAKEN CAREOF FOR YOU.

Page 36: Levelling up your WordPress development workflow

A GOOD STARTER THEME WILL ALSOTAKE CARE OF THINGS LIKE:

Basic CSS for WordPress functionality you may forgetabout (say, image alignment classes and galleries)Functions for common theme tasks (like setting up menusand widget areas)Adhering to (Underscores isespecially good with this for obvious reasons)

WordPress coding standards

Page 37: Levelling up your WordPress development workflow

STARTER THEMES FTW!THE TEDIOUS STUFF IS DONE FOR YOUAND THERE'S LITTLE TO NO STYLING

TO UNDO.

Page 38: Levelling up your WordPress development workflow

WHAT IF I TOLD YOU WE COULDTAKE THAT ONE STEP FURTHER?

Page 39: Levelling up your WordPress development workflow

THE BEST STARTER THEME...IS YOUR OWN, PERSONALIZED STARTER

THEME!No one knows your own coding style as well as you do.

Page 40: Levelling up your WordPress development workflow

MY STARTER THEME IS BASED ONUNDERSCORES AND CONTAINS:

A customized functions.php file with all my commonlyused functionsA starter script.js file with a few starter functions thatmost themes useAll my Sass partials set up as I like them with some usefulvariables and mixinsMy latest gulpfile.js and package.json (more on that in aminute)

Page 41: Levelling up your WordPress development workflow

2 EXAMPLE FUNCTIONS IN MY CUSTOMSTARTER THEME'S FUNCTIONS.PHP FILE

/** * Media - set default image link location to 'None' */

update_option('image_default_link_type','none');

/** * Always Show Kitchen Sink in WYSIWYG Editor */

function unhide_kitchensink( $args ) { $args['wordpress_adv_hidden'] = false; return $args;}

add_filter( 'tiny_mce_before_init', 'unhide_kitchensink' );

Page 42: Levelling up your WordPress development workflow

ANOTHER CUSTOM STARTER BONUSYou can bake in more accessibility feature than you'll find in

standard starters.

Page 43: Levelling up your WordPress development workflow

WHERE DO I KEEP MY STARTER THEME?There's no better place to store your starter theme than

or .GitHub Bitbucket

Page 44: Levelling up your WordPress development workflow

NOW, STARTING A NEW WORDPRESSPROJECT IS AS EASY AS:

1. Downloading WordPress and setting it up inMAMP/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 activatingyour starter theme

4. Git coding! Git it? Version control jokes are super cool.

Page 45: Levelling up your WordPress development workflow

NEVER USED GIT BEFORE?NO WORRIES!

I'll be talking more about it a little later and will give yousome good starter resources.

Page 46: Levelling up your WordPress development workflow

WORKFLOWIMPROVEMENT #3

GETTING A TASK RUNNERTO DO THE BORING STUFF

Page 47: Levelling up your WordPress development workflow

SOME OF MY FAVOURITEDEVELOPMENT TASKS INCLUDE:

Remembering which browser prefixes to use in CSSCompressing my imagesLinting and minifying JS filesCreating spritesConstantly refreshing my browser

Page 48: Levelling up your WordPress development workflow
Page 49: Levelling up your WordPress development workflow

THE SOLUTION

/

Page 50: Levelling up your WordPress development workflow

WHAT ARE GRUNT ANDGULP?

Built on

$ Run on the command line

Use plugins to run tasks

Page 51: Levelling up your WordPress development workflow

GRUNT OR GULP?

Page 52: Levelling up your WordPress development workflow

DEVS LOVE TO ARGUE

Page 53: Levelling up your WordPress development workflow

I PERSONALLY USE GULP.YOU HAVE MY BLESSING TO USE

EITHER ONE.

Page 54: Levelling up your WordPress development workflow

GULP PERFORMS TASKS THAT YOUCONFIGURE IN YOUR GULPFILE.JS.

Page 55: Levelling up your WordPress development workflow

YOUR PACKAGE.JSON FILE CONTAINSA LIST OF YOUR PROJECT'S

DEPENDENCIES (AKA GULP PLUGINS).

Page 56: Levelling up your WordPress development workflow

GULP SHOULD RUN IN YOUR THEMEDIRECTORY, NOT IN THE ROOTDIRECTORY OF YOUR WP

INSTALLATION.

Page 57: Levelling up your WordPress development workflow

MY STARTER THEME'S FILES

Page 58: Levelling up your WordPress development workflow

A FEW EXAMPLE GULPTASKS

Page 59: Levelling up your WordPress development workflow

CSS TASKSgulp.task('sass', function() { return gulp.src('style/style.scss') .pipe(sass()) .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6' .pipe(minifycss()) .pipe(gulp.dest(''))});

Page 60: Levelling up your WordPress development workflow
Page 61: Levelling up your WordPress development workflow

IN PLAIN ENGLISHGulp takes our Sass file...Turns it in to regular CSSRuns it through ...Minifies the CSS...And, finally, saves the CSS file.(All in a matter of milliseconds.)

Autoprefixer

Page 62: Levelling up your WordPress development workflow

CSS TASKSgulp.task('sass', function() { return gulp.src('style/style.scss') .pipe(sass()) .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6' .pipe(minifycss()) .pipe(gulp.dest(''))});

Page 63: Levelling up your WordPress development workflow

AUTOPREFIXER

Page 64: Levelling up your WordPress development workflow

TAKES THIS....thing-with-columns { column-count: 3; column-gap: 40px;}

...CHECKS CANIUSE.COM FORBROWSER SUPPORT...

Page 65: Levelling up your WordPress development workflow

AND GIVES YOU THIS..thing-with-columns { -webkit-column-count: 3; -moz-column-count: 3; column-count: 3; -webkit-column-gap: 40px; -moz-column-gap: 40px; column-gap: 40px}

:D

Page 66: Levelling up your WordPress development workflow

HOW TO RUN GULP TASKSType gulp [taskname] in your Terminal window.

Page 67: Levelling up your WordPress development workflow

JAVASCRIPT LINTINGgulp.task('lint', function() { return gulp.src('js/script.js') .pipe(jshint()) .pipe(jshint.reporter('default'));});

Page 68: Levelling up your WordPress development workflow
Page 69: Levelling up your WordPress development workflow

JS CONCATENATION +MINIFICATION

gulp.task('scripts', function() { return gulp.src(['js/plugins.js', 'js/script.js']) .pipe(concat('script.min.js')) .pipe(uglify()) .pipe(gulp.dest('js'));});

Page 70: Levelling up your WordPress development workflow

IMAGE COMPRESSIONgulp.task('images', function() { var imgSrc = 'img/source/*'; var imgDest = 'img';

return gulp.src(imgSrc) .pipe(newer(imgDest)) .pipe(imagemin()) .pipe(gulp.dest(imgDest));

});

Page 71: Levelling up your WordPress development workflow

BUT I SAVED THE BEST TASKFOR LAST

TYPING GULP SASS, GULP LINT, GULPSCRIPTS, AND GULP IMAGES OVER ANDOVER WOULD SURE GET ANNOYING,

RIGHT?

Page 72: Levelling up your WordPress development workflow

MY BFF, THE WATCH TASK gulp.task('watch', function() { // Listen on port 35729 server.listen(35729, function (err) { if (err) { return console.log(err) };

// Watch .js files gulp.watch('js/*.js', ['lint', 'scripts']);

// Watch .scss files gulp.watch('**/*.scss', ['sass']);

// Watch image files gulp.watch('img/source/*', ['images']); }); });

Page 73: Levelling up your WordPress development workflow

WATCHES FOR YOUR CHANGES......RUNS THE APPROPRIATE TASKS...... AND USES LIVERELOAD TO

AUTOMATICALLY REFRESH YOURBROWSER.

Page 74: Levelling up your WordPress development workflow
Page 75: Levelling up your WordPress development workflow

BUT... WHAT IF I'M SCAREDOF THE COMMAND LINE?

Page 76: Levelling up your WordPress development workflow

CODEKIT (MAC ONLY)

Page 77: Levelling up your WordPress development workflow

PREPROS(MAC, WINDOWS, LINUX)

Page 78: Levelling up your WordPress development workflow

GUIS CAN BE A GREAT PLACE TO START

Page 79: Levelling up your WordPress development workflow

LIKE GULP/GRUNT, CODEKIT/PREPROSALSO WATCHES YOUR THEME

DIRECTORY

Page 80: Levelling up your WordPress development workflow

GULP RESOURCESGetting started with gulpAn Introduction to Gulp.jsUsing Gulp for WordPress Theme DevelopmentWordPress theme development with Gulp, Bower, andSass

Page 81: Levelling up your WordPress development workflow

WORKFLOWIMPROVEMENT #4CSS PREPROCESSING

Page 82: Levelling up your WordPress development workflow

♥♥♥

Page 83: Levelling up your WordPress development workflow

VARIABLESPLAIN OL' CSS

.container { max-width: 980px; }

a { color: #b4c43d; font-family: 'Gotham A', 'Gotham B', sans-serif; }

Page 84: Levelling up your WordPress development workflow

VARIABLESSASS

// Fonts $gotham: 'Gotham A', 'Gotham B', sans-serif;

// Global information $pageWidth: 980px; $fontSize: 16px;

// Colours $green: #b4c43d; $teal: #73c6ba; $brown: #563016;

Page 85: Levelling up your WordPress development workflow

VARIABLESSASS

.container { max-width: $pageWidth; }

a { color: $green; font-family: $gotham; }

Page 86: Levelling up your WordPress development workflow

NESTINGPLAIN OL' CSS

.main-navigation { display: block; }

.main-navigation ul { list-style: none; } .main-navigation li { float: left; } .main-navigation a { color: #b4c43d; }

.main-navigation a:hover { color: #73c6ba; }

Page 87: Levelling up your WordPress development workflow

NESTINGSASS

.main-navigation { display: block; ul { list-style: none; } li { float: left; } a { color: $green; &:hover { color: $teal; } } }

Page 88: Levelling up your WordPress development workflow

PARTIALSDIVIDE YOUR STYLES INTO LOGICAL

SECTIONS

Page 89: Levelling up your WordPress development workflow

PARTIALS/*!Theme Name: Super Awesome ThemeTheme URI: http://fakeyfake.fakeAuthor: Dara SkolnickAuthor URI: http://daraskolnick.comDescription: The fakest theme in all the land*/

@import "partials/reset";

@import "partials/variables";

@import "partials/global";

@import "partials/forms";

@import "partials/nav";

@import "partials/pages";

@import "partials/posts";

@import "partials/widgets";

Page 90: Levelling up your WordPress development workflow

MATHPLAIN OL' CSS

.sidebar { width: 36.734693878%; /* 360px / 980px */ font-size: 1.3125em; /* 21px / 16px */ }

Page 91: Levelling up your WordPress development workflow

MATHSASS

.sidebar { width: 360px / 980px * 100%; font-size: 21px / 16px * 1em; }

Page 92: Levelling up your WordPress development workflow

MATHSASS

.sidebar { width: 360px / $pageWidth * 100%; font-size: 20px / $fontSize * 1em; }

Page 93: Levelling up your WordPress development workflow
Page 94: Levelling up your WordPress development workflow

WORKFLOWIMPROVEMENT #5DEPLOYING WITH GIT

Page 95: Levelling up your WordPress development workflow

BEFORE GIT...

...DEPLOYING SITES AND MAKINGCHANGES VIA FTP WAS A BIG PAIN.

Page 96: Levelling up your WordPress development workflow

HEY! WHAT'S WRONG WITHFTP?

SO GLAD YOU ASKED!

Sooooo slowEasy to forget which files need updatingTempting to make changes directly on the serverTherefore easy to get your local + remote copies out ofsync

Page 97: Levelling up your WordPress development workflow

DEPLOYING WITH GIT $ git add -A // adds all your changed files $ git commit -m "A message describing the changes you made" $ git push remote-name master // pushes your files to GitHub/Bitbucket/your site

Most projects of mine have three remotes: origin (Bitbucket),staging (my dev server) and live (client's server).

Page 98: Levelling up your WordPress development workflow

THIS IS AWESOME BECAUSE:Really easy (once you're used to it)Very quickNever have to remember which files you changed

Page 99: Levelling up your WordPress development workflow

OKAY, SO HOW DO I SET IT UP?

Page 100: Levelling up your WordPress development workflow

A FEW OPTIONS1. 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 whenyou push to Git

3. If your web host allows SSH access, set it up yourself viacommand line (e.g. , )

WP Engine

Deploy Beanstalk

Hostgator Bluehost

Page 101: Levelling up your WordPress development workflow

BUT I HAVE NO IDEA HOWTO USE GIT - HOW DO I

START?

Page 102: Levelling up your WordPress development workflow

RESOURCES FOR BEGINNERS:Learn Version Control with Gitgit - the simple guidetryGit

Page 103: Levelling up your WordPress development workflow

WORDPRESS-SPECIFIC GITRESOURCES

Version Controlling WordPressA WordPress & Git WorkflowWordPress Development and Deployment With MAMP,Git and Dropbox

Page 104: Levelling up your WordPress development workflow

IF GUIS ARE MORE YOUR STYLE / (free, and can be

used with non-GitHub remotes) ($, Mac only)

GitHub for Mac GitHub for Windows

Tower

Page 105: Levelling up your WordPress development workflow

IF DEPLOYING WITH GIT SEEMS TOOCOMPLEX FOR NOW...

Consider storing your client projects in private repositoriesto start.

Builds good habits and makes it easier to collaborate withother developers.

Page 106: Levelling up your WordPress development workflow

MY BITBUCKET ACCOUNT - PUBLIC VIEW

Page 107: Levelling up your WordPress development workflow

MY BITBUCKET ACCOUNT - LOGGED IN

Page 108: Levelling up your WordPress development workflow

YOU MIGHT BE FEELING LIKE THISRIGHT NOW

Page 109: Levelling up your WordPress development workflow

FEELING OVERWHELMED?Don't worry about doing everything at onceEven the smallest workflow tweaks will save time

Page 110: Levelling up your WordPress development workflow

THANKS!ANY QUESTIONS?

@DARASKOLNICK

DARASKOLNICK.COM