RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (5.84%*) • Fixed: 5.39% (5.84%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.19%*) • Investment PI: 5.55% (6.02%*)

Mobile Design Considerations with WordPress and PHP

Mobile Design Considerations with WordPress and PHP

In another article ("How Important is Your Mobile Optimised Website?") we looked at numerous issues associated with optimising your mobile website experience. This article will expand upon the question of how to bounce your users back and forth between both sites (assuming you're using a separate m.website and not a responsive design). We'll also look at basic principles you may use to tailor specific content for different types of users.

The complexity of devices used to view content means that we have to think of alternate and clever ways of accommodating all devices in a way that enhances the user experience... and this article seeks to look at just a few different ways we can deliver on that expectation.

The following is discussed in brief:

  • Bidirectional, Unidirectional, and No Redirects - To redirect or not redirect? That is the question.
  • Fixed Footer with Redirect Link - simple footer link that provides the option of bouncing between desktop and mobile devices.
  • Detecting Screen Width with JavaScript.
  • Detect Mobile Browsers with a (User Agent) Regex.
  • Redirections with .htaccess.
  • CSS Media Queries.
  • Conclusion.

Bidirectional, Unidirectional, and No Redirects

You can set up your sites in numerous ways; redirect your mobile users to a mobile version when requesting the desktop website, or visa-versa, or you may request desktop and mobile users both ways depending upon the platform from which they're making the request. While the redirects are easy to implement, we'll focus on no redirects. From personal experience, I prefer to see the website that I request. Desktop designed sites are easier to navigate around large amounts of content - particularly on a tablet. In consideration of the user experience, sometimes providing a choice is the better option.

Fixed Footer with Redirect Link

The first lot of code is based upon the fixed bar code we previously shared. It'll simply render an unobtrusive fixed bar at the top or bottom of your page and provide a link to the alternate site. It's based on either identical permalinks (easy to do with WordPress) or with an alternate URL stored as a post option. The example link at the bottom of this page to would bounce the user between m.beliefmedia.com and the desktop site. A cookie or session option should be provided to remove the bar completely.

The platform making the request is identified by the WordPress wp_is_mobile() function. It's a conditional tag that checks if the user is visiting using a mobile device and returns a Boolean TRUE or FALSE. The function, located in wp-includes/vars.php identifies the device by testing the $_SERVER['HTTP_USER_AGENT'] string. It's a basic function and WP make the point that it does not consider resolution, window width, or any other factors. They state that it shouldn't be used for themes (instead referring developers to the Mobble plugin that'll detect devices with is_iphone, is_mobile, and is_tablet).

It's virtually impossible to provide a universal example because it's unknown how you'll be setting up your site with relation to database access.

So, as an example, here's code that'll conditionally provide a mobile or desktop redirection link based on the current permalink.

1
<?php 
2
/*
3
 Redirect Users to Your Mobile or Desktop Website (with WordPress or PHP) or Customise Mobile Content
4
 http://www.beliefmedia.com/mobile-redirects
5
*/
6
 
7
function beliefmedia_fixed_mobile_footer() {
8
 $permalink = get_permalink();
9
 if (wp_is_mobile()) {
10
  /* Conditional code to check the URL and adjust for desktop site */
11
  echo '<div style="position: fixed; z-index: 5; bottom: 0; width: 100%; color: #ffffff; line-height: 20px; text-align: center; padding-bottom: 2px; padding-top: 2px; -webkit-box-shadow: 0px 0px 8px 0px #000000; -moz-box-shadow: 0px 0px 8px 0px #000000; box-shadow: 0px 0px 8px 0px #000000; background-color: rgba(1, 1, 1, 0.8); color: rgba(1, 1, 1, 0.8);">
12
<div class="bm_mobile_fixedbar" style="color: white; text-decoration: bold; font-size: 11px;">Visit our desktop website <a href="' . $desktopURL . '">here</a></div>
13
</div>';
14
   } else {
15
  /* Conditional code to check the URL and adjust for mobile site */
16
  echo '<div style="position: fixed; z-index: 5; bottom: 0; width: 100%; color: #ffffff; line-height: 20px; text-align: center; padding-bottom: 2px; padding-top: 2px; -webkit-box-shadow: 0px 0px 8px 0px #000000; -moz-box-shadow: 0px 0px 8px 0px #000000; box-shadow: 0px 0px 8px 0px #000000; background-color: rgba(1, 1, 1, 0.8); color: rgba(1, 1, 1, 0.8);">
17
<div class="bm_mobile_fixedbar" style="color: white; text-decoration: bold; font-size: 11px;">Visit our mobile website <a href="' . $mobileURL . '">here</a></div>
18
</div>';
19
  }
20
 }
21
add_action('wp_footer', 'beliefmedia_fixed_mobile_footer');

While you can easily determine the URL of an alternate m.site, you could optionally record the URL of the other website using get_post_meta() - particularly if the URLs are differed or weren't based off the same permalink.

We generally write inline CSS to negate the need and overhead associated with adding CSS to another file (or adding it to a custom plugin). However, a* links form part of the selector (outside the wiggly brackets) which is implicit to the current element, or div - while inline styles only have rules. So, if you're like me and your default link text conflicts with the color of the fixed redirect bar, you must upload the following CSS to the CSS file attached to your custom functions plugin to style the message bars links.

1
/*
2
 Redirect Users to Your Mobile or Desktop Website (with WordPress or PHP) or Customise Mobile Content
3
 http://www.beliefmedia.com/mobile-redirects
4
*/
5
 
6
div.bm_mobile_fixedbar a:visited {
7
  color: #FE6915;
8
}
9
 
10
div.bm_mobile_fixedbar a:link {
11
  color: #FE6915;
12
}
13
 
14
div.bm_mobile_fixedbar a:hover {
15
  color: #ffffff;
16
}

I had some issues with some mobile browsers rending the CSS. To remedy that, I saved the CSS as UTF-8 and put the following line at the top of my style sheet.

1
@charset "UTF-8";

If used on an actual mobile site the fixed bar would look as follows:

Mobile Design Considerations with WordPress and PHP

When you squeeze up your responsive design as if it were viewed on a mobile, you can see there are elements that might be best removed. In my case, the Twitter button, Facebook share buttons, fancy date, and featured image might be best left excluded from rendering. This can all be accomplished with wp_is_mobile(), although you might only remove it for mobile handsets rather than all tablet-type devices. While Mobble makes serving the conditional content easy, you might also consider JavaScript.

Detecting Screen Width with JavaScript

JavaScript isn't overly effective for the purpose of the redirect, and a user agent string is almost always more efficient. However, you can use JavaScript as follows:

1
<script type="text/javascript">
2
<!--
3
if (screen.width <= 699) {
4
document.location = "mobile-website.html";
5
}
6
//-->
7
</script>

You can optionally detect specific mobile phones, or various ranges of resolution, and redirect them as appropriate. It's not uncommon for those with a big budget to create a mobile, tablet, and a desktop version of the same website. For example, I can detect the dimensions of your device. [dimensions]. Knowing the dimensions of the majority of major devices, or grouping them by size, we can conditionally redirect them to alternate websites.

Incidentally, I used the following shortcode to print the dimensions of your device to your page:

1
<?php 
2
/*
3
 Determine Screen Dimensions and return with WP shortcode
4
 Redirect Users to Your Mobile or Desktop Website (with WordPress or PHP) or Customise Mobile Content
5
 http://www.beliefmedia.com/mobile-redirects
6
*/
7
 
8
function beliefmedia_detect_screen_dimensions() {
9
 
10
 $return = '<span id="dimension"></span>';
11
 
12
  $return .= '<script>';
13
  $return .= 'var txt = "";';
14
  $return .= 'txt += screen.width + " x " + screen.height;';
15
  $return .= 'document.getElementById("dimension").innerHTML = txt;';
16
  $return .= '</script>';
17
 
18
 return $return;
19
}
20
add_shortcode('dimensions', 'beliefmedia_detect_screen_dimensions');

Detect Mobile Browsers with a (User Agent) Regex

Chad Smith has written a fairly comprehensive regex that, not unlike WordPress, redirects by virtue of the HTTP_USER_AGENT. It'll detect most mobile browser and redirect to a mobile source. In reality, you would want to conditionally check for smaller devices like mobile phones, and tablets, and redirect them appropriately.

Used in a shortcode, and assuming you're reading on a mobile device, I can render your browser as "[useragentmobile]".... although you could use a modified regex to check for desktop browser types as well. Here's Chad's regex that'll redirect to a mobile website.

1
<?php 
2
$useragent=$_SERVER['HTTP_USER_AGENT'];
3
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|android|ipad|playbook|silk|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4)))
4
header('Location: http://detectmobilebrowser.com/mobile');

If you would like to see a comprehensive list of all supported devices and user strings, download the list here .

Your User Agent is: [useragent]. It's this string we read to make a determination of what device you're using.

Included for your reference only, I've used the following simple shortcode to display your user agent sting:

1
<?php 
2
/*
3
 Print User Agent to Screen
4
 Redirect Users to Your Mobile or Desktop Website (with WordPress or PHP) or Customise Mobile Content
5
 http://www.beliefmedia.com/mobile-redirects
6
*/
7
 
8
function beliefmedia_resolve_useragent() {
9
  $useragent = $_SERVER['HTTP_USER_AGENT'];
10
 return $useragent;
11
}
12
add_shortcode('useragent', 'beliefmedia_resolve_useragent');

If we were to modify Chad's regex slightly to just include only the first preg_match (for simplicity), we could make a determination of what device our visitor might be using and conditionally direct them to a specific website. The user string is rather complex and generally an inefficient means for detecting a device (it detects a browser, or software agent ), however, while imperfect, it's still extremely reliable by design. The W3C recommends creating HTML markup that is standard, allowing correct rendering in as many browsers as possible, and to test for specific browser features rather than particular browser versions or brands.

Following this paragraph is the shortcode I used to print the mobile useragent match to your screen. While the purpose of this article is to discuss redirects, the code could be used to offer a download for a specific application from either the App Store or Google Play. You could alternatively simply deliver different content to different users... or product accessories that you know the visitor has (why sell an iPhone cover to an Android user?)... knowing the device your visitor is using offers interesting ways of split-testing. Given that iPhone owners apparently make an average $85,000 per year compared to Android's 61,000 per year, and armed with a location that you can easily obtain, you might be able to tailor advertising that is more likely to convert. It's interesting to think of how little bits of knowledge like this can be used.

1
<?php 
2
/*
3
 Print User Agent to Screen
4
 Redirect Users to Your Mobile or Desktop Website (with WordPress or PHP) or Customise Mobile Content
5
 http://www.beliefmedia.com/mobile-redirects
6
*/
7
 
8
function beliefmedia_mobile_browser() {
9
  preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i', $useragent, $matches);
10
  $return = ($matches['1'] != '') ? $matches['1'] : 'desktop';
11
 return $return;
12
}
13
add_shortcode('useragentmobile', 'beliefmedia_mobile_browser');

The same device-specific redirects can be accomplished less efficiently with JavaScript.

Using WordPress wp_is_mobile() Outside of WordPress

The wp_is_mobile() function can be used in any application.

1
<?php 
2
/*
3
 Redirect Users to Your Mobile or Desktop Website (with WordPress or PHP) or Customise Mobile Content
4
 http://www.beliefmedia.com/mobile-redirects
5
*/
6
 
7
function beliefmedia_wp_is_mobile() {
8
  static $is_mobile = null;
9
  if ( isset( $is_mobile ) ) {
10
    return $is_mobile;
11
  }
12
  if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
13
    $is_mobile = false;
14
   } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
15
      || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
16
      || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
17
      || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
18
      || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
19
      || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
20
      || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
21
      $is_mobile = true;
22
   } else {
23
    $is_mobile = false;
24
  }
25
 return $is_mobile;
26
}

Usage:

1
<?php 
2
/* Returns TRUE or FALSE */
3
echo (beliefmedia_wp_is_mobile() !== false) ? 'Mobile' : 'Not Mobile';

While it's an imperfect function, we can modify it slightly to identify specific types of browsers based on the user agent (instead of returning a Boolean). This gives us some of the features of Chad's function in that our code may return an identified device (however reliable). Again, it's just a modified version of the WP function so shouldn't be used for important applications.

1
<?php 
2
/*
3
 Redirect Users to Your Mobile or Desktop Website (with WordPress or PHP) or Customise Mobile Content
4
 http://www.beliefmedia.com/mobile-redirects
5
*/
6
 
7
function beliefmedia_is_mobile() {
8
 
9
  $userstring = $_SERVER['HTTP_USER_AGENT'];
10
 
11
   switch ($userstring) {
12
    case strpos($userstring, 'Android') !== false:
13
     $device = 'Android';
14
     break;
15
    case ( strstr($userstring,'iPhone') || strstr($userstring,'iPod') ) !== false:
16
     $device = 'iPhone';
17
     break;
18
    case strpos($userstring,'iPad') !== false:
19
     $device = 'iPad';
20
     break;
21
    case (preg_match('[iemobile|ppc|smartphone]', $userstring) === true):
22
     $device = 'Windows';
23
     break;
24
    case strpos($userstring, 'Silk/') !== false:
25
     $device = 'Silk';
26
     break;
27
    case strpos($userstring, 'Kindle') !== false:
28
     $device = 'Kindle';
29
     break;
30
    case strpos($userstring, 'BlackBerry') !== false:
31
     $device = 'BlackBerry';
32
     break;
33
    case strpos($userstring, 'Opera Mini') !== false:
34
     $device = 'Opera';
35
     break;
36
    case strpos($userstring, 'Opera Mobi') !== false:
37
     $device = 'Opera Mobi';
38
     break;
39
    case (preg_match('[kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap]', $userstring) === true):
40
     $device = 'Generic';
41
     break;
42
    default:
43
     $device = false;
44
     break;
45
   }
46
 return ($device) ? $device : 'Unknown';
47
}
48
 
49
/* Usage */
50
echo beliefmedia_is_mobile();

Redirections with .htaccess

You might also consider applying redirections at the server level before headers are served. Here's an example .htaccess file that'll redirect on identifying an iPad.

1
RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
2
RewriteRule ^(.*)$ http://ipad.beliefmedia.com [R=302]

A 302 redirect is used (temporarily moved) rather than a 301 as per Google's guidelines. The same code applies to identifying Android devices.

1
RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
2
RewriteRule ^(.*)$ http://android.beliefmedia.com [R=302]

Here's a good solution to .htaccess redirects that I found on StackOverflow a few years ago:

1
RewriteEngine on
2
RewriteBase /
3
# Check if this is the noredirect query string
4
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
5
# Set a cookie, and skip the next rule
6
RewriteRule ^ - [CO=mredir:0:www.beliefmedia.com]
7
 
8
# Check if this looks like a mobile device
9
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
10
RewriteCond %{HTTP:Profile}       !^$ [OR]
11
RewriteCond %{HTTP_USER_AGENT} &quot;acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-&quot; [NC,OR]
12
RewriteCond %{HTTP_USER_AGENT} &quot;dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-&quot; [NC,OR]
13
RewriteCond %{HTTP_USER_AGENT}  &quot;maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv&quot; [NC,OR]
14
RewriteCond %{HTTP_USER_AGENT} &quot;palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany&quot; [NC,OR]
15
RewriteCond %{HTTP_USER_AGENT} &quot;sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo&quot; [NC,OR]
16
RewriteCond %{HTTP_USER_AGENT} &quot;teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi&quot; [NC,OR]
17
RewriteCond %{HTTP_USER_AGENT} &quot;wapp|wapr|webc|winw|winw|xda|xda-&quot; [NC,OR]
18
RewriteCond %{HTTP_USER_AGENT} &quot;up.browser|up.link|windowssce|iemobile|mini|mmp&quot; [NC,OR]
19
RewriteCond %{HTTP_USER_AGENT} &quot;symbian|midp|wap|phone|pocket|mobile|pda|psp&quot; [NC]
20
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
21
 
22
# Check if we're not already on the mobile site
23
RewriteCond %{HTTP_HOST} !^m\.
24
# Can not read and write cookie in same request, must duplicate condition
25
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$)
26
 
27
# Check to make sure we haven't set the cookie before
28
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
29
 
30
# Now redirect to the mobile site
31
RewriteRule ^ http://m.beliefmedia.com [R,L]

From what I can tell so far it works quite well. While server based redirections are fraught with potential danger (they'll force a redirect even if the user chooses against it), this code provides for an option in the query string &m=0 (and a Cookie will be set) to ensure that you can escape the redirect measures.

Redirect Before Content is Served

In all cases where you're redirecting from one page to another, you should provide for a header redirect before any content (including spaces) are sent to the screen.

In PHP, you'll generally use something as follows:

header("Location://m.beliefmedia.com/", 302);

Note the 302 redirect (as recommended by Google for mobile redirects). If the status code is not specified, header('Location:') should default to 302.

When using WordPress, a good action to use before any content is rendered to your page is template_redirect . While PHP's header("Location: .. is acceptable, WordPress have their own wp_redirect function. It differs from PHP's default function in that it sanitises URLs, applies filters, and corrects redirects on some server setups. All header redirects used in templates and other code must be run before get_header() (we use template_redirect for an upcoming article on under construction pages, and it works well).

CSS Media Queries

Media Queries are a CSS3 module allowing content rendering to adapt to conditions such as screen resolution. It became a W3C recommended standard in June 2012 and is the cornerstone technology of responsive web design.

This is a demo paragraph. Scale the screen size and it'll change color at 500 pixels. Scale your browser and try it out.

For those that can't see it, this:

Mobile Design Considerations with WordPress and PHP

... becomes this:

Mobile Design Considerations with WordPress and PHP

I've used a simple media query as follows:

1
@media only screen and (max-width: 500px) {
2
  .mobilecolordemo {
3
    background-color: #EDFE14;
4
  }
5
}

... and my HTML looks like this:

Mobile Design Considerations with WordPress and PHP

Media queries mean that you can load CSS conditional on the device used, and you can seriously alter the design based on how it's viewed. It's a client-side solution to rendering conditional content that could be used, for example, to hide the interstitial advertising that Google will now penalise mobile websites for displaying. For example, here's a fairly crude example of a paragraph that will display content based on the device you're viewing it on (or the browser width). If you're on a desktop, you can scale your browser and the message will change as it gets narrower:

Content for a desktop device...

Content for a tablet device...

Content for a mobile...

The paragraph will conditionally display a message that says "Content for a (desktop|tablet|mobile) device". I've plucked the dimensions from nowhere so they mean nothing; it just worked for the example. Think about how this might be used to display social links, newsletter subscriptions, advertising, and so on.

The CSS to accomplish what I've demonstrated:

1
@media screen and (min-width:800px) {
2
  .mobiledemocontent .large {
3
    display:block;
4
  }
5
  .mobiledemocontent .medium {
6
    display:none;
7
  }
8
  .mobiledemocontent .small {
9
    display:none;
10
  }
11
}
12
 
13
@media screen and (min-width:600px) and (max-width:799px) {
14
  .mobiledemocontent .large {
15
    display:none;
16
  }
17
  .mobiledemocontent .medium {
18
    display:block;
19
  }
20
  .mobiledemocontent .small {
21
    display:none;
22
  }
23
}
24
 
25
@media all and (max-width: 599px) {
26
  .mobiledemocontent .large {
27
    display:none;
28
  }
29
  .mobiledemocontent .medium {
30
    display:none;
31
  }
32
  .mobiledemocontent .small {
33
    display:block;
34
  }
35
}

... and the HTML:

1
<div class="mobiledemocontent">
2
<div class="large">Content for a desktop device...</div>
3
<div class="medium">Content for a tablet device...</div>
4
<div class="small">Content for a mobile...</div>
5
</div>

Read more about CSS Media Queries here .

Conclusion

All the subject matter on this page was nothing more than a cursory introduction for those that are looking at venturing into the world of mobile design. The customized user-experience will yield better results than a generic one-size-fits-all approach. Fortunately, WordPress and other CMS platforms or frameworks provide a basis from which we can build.

This article was originally published on Internoetics in 2015. It may contain content that is a little outdated.

If you're looking to enhance your mobile experience, get in touch with us.

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment