Jason McCreary

a PHP and iOS developer. a thinker.

My Talk at WordCamp Chicago: Configuring WordPress for Multiple Environments

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):

<?php
if (VIA_ENVIRONMENT == 'prod') {
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-#######-#']);
_gaq.push(['_trackPageview']);
(function () {
    var ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
}
?> 

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

<?php
if (VIA_ENVIRONMENT == 'dev') {
?>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/res/css/global.css" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/res/css/off-season.css" />
<!--[if lte IE 7]><link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/res/css/ie.css" type="text/css" media="all" /> <![endif]-->
<?php
}
else {
?>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/res/css/global-1.0.min.css" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/res/css/off-season-0.2.min.css" />
<!--[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]-->
<?php
}
?>

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!

Comments