Responsive design is slowly but surely becoming an expected standard for web developers. This tutorial will show you how to add a responsive framework to your next WordPress theme.
What Is Responsive Design?
It used to be you only had to worry about website consistency across multiple browsers, but now we have to look at the bigger picture – consistency across multiple devices. The computer used to be our only gateway to the Internet, but now we jump online from our phones, TVs, tablets and who knows what else will come down the pipe. Having your website appropriately render and perform on any device should be a top priority this year.
Responsive design is all about making things fluid and adjusting according to screen size. Although WordPress doesn't always play nice with responsive design methods, there are ways it can be achieved. How responsive you decide to make your website is really about how much time you want to spend doing it.
Responsive Frameworks
There are several responsive frameworks out there to choose from. You might want to spend some time investigating each one to determine which has the included features your project might require. If you aren't sure where to start, here are a few to consider:
Bootstrap
Bootstrap from Twitter is built on a responsive 12 column grid. It has included fixed- and fluid-width layouts based on that system. It also comes with support for optional JavaScript plug-ins such as an image carousel, Typeahead, togglable tabs, and many more.
Less Framework
Less Framework is based on 4 layouts and 3 sets of typographic presets. Less Framework uses a default layout as a starting point and then uses CSS3 media queries to code 'child layouts'.
Foundation
Foundation is a grid system based on 12-columns that do not have a fixed width; they can vary based on the resolution of the screen or size of the window. Foundation comes pre-packaged with buttons and built in form styles, alerts, and more.
YAML
YAML is a multi-column layout based on a grid system with percentage widths. It comes with several built in features and supports several jQuery plugins such as Accessible Tabs and SyncHeight.
This list of frameworks is hardly complete, but for the sake of this tutorial, I'm going to show you how to incorporate Foundation into your next WordPress theme.
Step 1 Downloading and Applying the Framework
To get started, go download Foundation and add the files to your css and js folders in your theme's directory. The easiest way to add the required files to your theme would be to use wp_enqueue_script
and wp_enqueue_style
.
For this tutorial I'm going to show you what you place in your functions.php file to make Foundation work right off the bat, but for more details on adding files this way, check out the tutorial on how to include JavaScript and CSS in your theme.
To add the needed JavaScript for Foundation to work properly in your theme, you need to create a function that calls the wp_enqueue_script
to serve them up.
function responsive_scripts_basic() { //register scripts for our theme wp_register_script('foundation-mod', get_template_directory_uri() . '/js/modernizr.foundation.js', array( 'jquery' ), true ); wp_register_script('foundation-main', get_template_directory_uri() . '/js/foundation.js', true ); wp_register_script('foundation-app', get_template_directory_uri() . '/js/app.js', true ); wp_enqueue_script( 'foundation-mod' ); wp_enqueue_script( 'foundation-main' ); wp_enqueue_script( 'foundation-app' ); } add_action( 'wp_enqueue_scripts', 'responsive_scripts_basic', 5 );
Next, add the Foundation stylesheets to make the grid flexible. Paste this function after the one you just created.
function responsive_styles() { //register styles for our theme wp_register_style( 'foundation-style', get_template_directory_uri() . '/css/foundation.css', array(), 'all' ); wp_register_style( 'foundation-appstyle', get_template_directory_uri() . '/css/app.css', array(), 'all'); wp_enqueue_style( 'foundation-style' ); wp_enqueue_style( 'foundation-appstyle' ); } add_action( 'wp_enqueue_scripts', 'responsive_styles' );
Once saved, go back and check your source code to make sure your files were added correctly. It should look something like this:
<link rel='stylesheet' id='foundation-style-css' href='http://thatonegeek.com/sandbox/wp-content/themes/Starkers/css/foundation.css?ver=all' type='text/css' media='all' /> <link rel='stylesheet' id='foundation-appstyle-css' href='http://thatonegeek.com/sandbox/wp-content/themes/Starkers/css/app.css?ver=all' type='text/css' media='all' /> <script type='text/javascript' src='http://thatonegeek.com/sandbox/wp-includes/js/jquery/jquery.js?ver=1.7.1'></script> <script type='text/javascript' src='http://thatonegeek.com/sandbox/wp-content/themes/Starkers/js/modernizr.foundation.js?ver=1'></script> <script type='text/javascript' src='http://thatonegeek.com/sandbox/wp-content/themes/Starkers/js/foundation.js?ver=3.3.1'></script> <script type='text/javascript' src='http://thatonegeek.com/sandbox/wp-content/themes/Starkers/js/app.js?ver=3.3.1'></script>
Step 2 Add IE Only Conditions
Everyone loves to go that extra mile to make things work in Internet Explorer right? To make sure your Foundation framework stays responsive in Internet Explorer, you need to add a few conditional statements. These should go in your header.php file before the closing head tag.
<!--[if lt IE 9]> <link rel="stylesheet" href="/css/ie.css"> <![endif]--> <!--IE Fix for HTML5 Tags--> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->>
Step 3 Working With the Framework
Now that your theme has Foundation setup, to make use of all its responsive features you need to design using the Foundation grid system. Like other responsive frameworks, it's a system made up of 12 columns. Other included features are pre-set button styles, tabs, tables and much more. Check out the Foundation documentation to view all bells and whistles and instructions on how to work with the grid.
Going With a Pre-Packaged Theme
There are plenty of free and premium WordPress themes available that make use of responsive design. If you would rather start with something out of the box, you can try out these themes:
WordPress Bootstrap, By 320Press
WordPress Bootstrap is a theme developed on Twitter's Bootstrap v.2.0.1. It's fully responsive with four different page templates to choose from, shortcodes, and multiple sidebar options. Once installed, you can check out bootswatch.com to download different color versions of the theme.
iTheme2
Based on the Themify framework, iTheme2 uses media queries to target different displays, comes with a customizable feature slider, a social media widget, two different theme skins and you can have up to four footer widgets.
Responsive Twenty Ten
The Responsive Twenty Ten theme supports flexible images, margins, and mobile images. It was created as a child theme for the included Twenty Ten theme.
Good Minimal (Premium)
Good Minimal is a clean, minimalist responsive layout that adapts to a multitude of displays and devices. Good Minimal comes with two different styles, supports unlimited custom sidebars, shortcodes, multiple drop down menus, and several other features.
Modulo (Premium)
Modulo is a responsive, fluid layout, supporting google fonts, shortcodes, multiple sliders, portfolio page templates and color customization. Modulo also comes with 5 custom widgets, including one for recent posts with thumbnail support.
Conclusion
Responsive design is continuing to grow in popularity and knowing how to utilize it within your future theme construction will be crucial for success. Whether you are adding a framework to your theme or using a pre-built theme supporting responsive design, your clients are going to expect multiple device support as a basic service.
Are themes you create responsive? Do you use a responsive framework we haven't mentioned? Tell us all about it in the comments below!
If you need help creating a responsive WordPress site design, try ordering one of the easy, cost-effective WordPress services on Envato Studio. These expert providers will take your design and convert it to a responsive WordPress site quickly and without hassle!
Comments