How to Disable Mobile Theme in WordPress

With smartphone usage on the rise, you might wonder why anyone would want to disable mobile support in WordPress (specifically, in the Twenty Eleven theme).  Answer: It’s poorly implemented, or at minimum sub-optimal in its default settings.

Default WordPress mobile theme view

While the readability of each post is improved by laying out the main post area as full width, by placing the sidebars at the bottom, your readers may miss any content you are hoping to share.  For this website, the search button, social networking buttons, and Twitter feed information are shown at the bottom of the site layout (see picture on left).  It’s not the end of the world, but not ideal either.

To make things worse, if you start making changes to your CSS file to customize the theme and aren’t careful, the mobile theme will get mangled.  In my case, I assume that because I specified some of my width parameters in pixels instead of percentages, the mobile theme doesn’t know how to display them.  But, since the traffic to this blog is mainly from desktop/laptop computers (which I know because I’m using Google Analytics!), I’ll optimize the blog design to non-mobile devices at the risk of mangling the mobile theme.

Luckily, what makes the mobile theme sub-optimal when using the Twenty Eleven theme is what makes it so easy to disable the mobile theme!

Disable the “viewport”

In order to turn off the mobile theme, all we need to do is comment out a single line of code within our header.php file.  The line we are looking for is a meta tag that refers to the “viewport”, which is a mobile META tag to specify dimensions for a mobile browser to use, and well as control/modify some functionality such as browser scaling (zoom).  Here’s what the commented out code should look like:

<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<!-- <meta name="viewport" content="width=device-width" /> -->

Any CSS mods and the mobile theme breaks down

Inside of this META tag, the “content” parameter specifies that the mobile browser should set the width of the content equal to whatever the device width is currently set.  So in the case of iPhones where the width varies depending on the phone orientation, the browser will re-size the content appropriately.

But, what if I want to just improve the mobile browser experience?

Obviously, just because the default mobile functionality in this theme doesn’t work very well, that doesn’t mean your desktop theme is ideal either.  If you want to design a mobile theme, you can use this same “Viewport” line of code to play around with the settings, hopefully finding ones that not only make your site look great, but are also compatible with the range of smartphones on the market.

For an explanation of all of the parameters that can be changed as part of the Viewport META tag, see this article from ‘Learn the Mobile Web’.


Comments

  1. mjmcclain says:

    <head>
    <meta charset=”<?php bloginfo( ‘charset’ ); ?>” />
    <?php if ( ! $yiw_mobile->isIpad() ) : ?>
    <meta name=”viewport” content=”width=device-width” /><?php endif ?>
    <title>
     
    Above you will find the code in my header.  Can you tell me if I have to do anything with the (php line) in between the two “meta” lines?
     
    Thank you.

    • Randy Zwitch says:

      What your code is doing is saying “If not an iPad, then show the mobile theme”.

      Without being able to test, I think you should be able to comment out the PHP block if you want to disable the mobile theme altogether. You just need to put “/*” (without quotation marks) before the < ?php reference, and put a "*/" after the last "?>” piece of code.

      If that doesn’t work, let me know what theme you are using and I’ll see if I can help.

  2. Thank you so much!

%d bloggers like this: