Put Your Code Pants On

Be responsible with your code

  • get organized
  • version it
  • if possible, work locally

I know you can “just go in and change that one line”. What happens when that one change mushrooms into a rabbit hole?

Slow is safe, safe is fast.

Compartmentalize your code

Compare header.php in Twenty Ten vs. Twenty Fourteen. Look at how all the calls to css & javascript got moved to to functions.php, loaded through twentyfourteen_scripts()
Try not to repeat yourself – if you wind up writing the same code twice, you could probably rewrite it to account forbeing used more than once.

Learn by doing

If it’s been in WordPress since 3.0, learn how to do it without a plugin.

Organize your stylesheet

Think of your theme in a mobile-first mindset.

When you write your CSS, avoid mixing widths and other positioning CSS with typography, backgrounds, and colors. Move all the positioning & dimensional styles into media breakpoints to avoid repeating styles.

Don’t hard-link scripts, css, or URLs

Use wp_enqueue_style() and wp_enqueue_script() to load your CSS and Javascript with any necessary dependencies ( jQuery, etc. )
Use the various “url” functions for src or href attributes in your templates: home_url(), get_template_directory_uri(), etc. Try to avoid writing out things like href="/my-page" because your site may get moved to a subdirectory and that relative path will break. Use something likea href="<?php echo home_url(); ?>/my-page"

Versioning ( git ):

Learn the basics of the command line:
http://www.siteground.com/tutorials/git/commands.htm
http://gitref.org/basic/

In actual day-to-day use of Git , SVN, etc, there’s nothing wrong with a GUI tool

Working Locally

  • Save yourself time.
  • Avoid relying on crappy network connections.

Local dev tools:

%d bloggers like this: