My Talk at WordCamp Chicago: Configuring WordPress for Multiple Environments

Main Thread Talks 2 min read

UPDATE: This talk has been posted on WordPress.tv.

I just completed my talk on Configuring WordPress for Multiple Environments at WordCamp Chicago. Probably close to a hundred in the crowd. Being only my second talk, it was a bit intimidating. But the feedback has been positive. So much so that I've been asked to release my code samples and slides immediately.

The Talk

The talk was an evolution from an earlier blog post of the same name – Configuring WordPress for Multiple Environments. It includes a detailed write-up and code samples (although they might be dated).

The Slides

The slides for the talk will eventually be on SlideShare. For now you can download my slides as a PDF. There were several demos. I tried to include a summary slide after each demo slide. Nonetheless, code samples are below and you can always contact me for more detail.

The Code

Environment Awareness

The following demonstrate using the VIA_ENVIRONMENT constant to perform environment specific code.

Include Google Analytics in just Production (in theme's header.php):

1<?php
2if (VIA_ENVIRONMENT == 'prod') {
3?>
4<script type="text/javascript">
5var _gaq = _gaq || [];
6_gaq.push(['_setAccount', 'UA-#######-#']);
7_gaq.push(['_trackPageview']);
8(function () {
9 var ga = document.createElement('script');
10 ga.type = 'text/javascript';
11 ga.async = true;
12 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
13 var s = document.getElementsByTagName('script')[0];
14 s.parentNode.insertBefore(ga, s);
15})();
16</script>
17<?php
18}
19?>

Use minified resources for any non-Development environment (in theme's header.php):

1<?php
2if (VIA_ENVIRONMENT == 'dev') {
3?>
4<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/res/css/global.css" />
5<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/res/css/off-season.css" />
6<!--[if lte IE 7]><link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/res/css/ie.css" type="text/css" media="all" /> <![endif]-->
7<?php
8}
9else {
10?>
11<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/res/css/global-1.0.min.css" />
12<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/res/css/off-season-0.2.min.css" />
13<!--[if lte IE 7]> <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/res/css/ie-0.2.min.css" type="text/css" media="all" /> <![endif]-->
14<?php
15}
16?>

Setting up a WordPress development environment Unconference

After strong interest I have spoken with the WordCamp Chicago organizers about adding an unconference. We've been approved to use the open time slot from 9:00-10:00 Sunday morning. I will be helping anyone interested in setting up a local development environment on their Mac. If you'd like to do so on a different OS I will try to find additional moderators. Please reach out to me at the after-party or on Twitter, @gonedark, if you plan to attend.

See you at the after-party!

Find this interesting? Let's continue the conversation on Twitter.