Louismoore18
Louismoore18

Reputation: 167

Disabling mobile view for wordpress theme

I'm looking for a way to disable the mobile view when viewing on my iPhone for my website. Is there a plug in or some code that can do this?

My theme is starkers-master and there's no option with this to do so

Upvotes: 0

Views: 51118

Answers (5)

Ji't
Ji't

Reputation: 11

It seems this is a pretty old post but it's easier to achieve this now.

From the docs:

<?php if ( wp_is_mobile() ) : ?>
    /* Display and echo mobile specific stuff here */
<?php else : ?>
    /* Display and echo desktop stuff here */
<?php endif; ?>

Upvotes: -1

Michael Ifeanyi
Michael Ifeanyi

Reputation: 39

I was able to disable mobile view on my wordpress site by simply Going to Appearance > Theme Editor. Then From the Theme Files on the right-side of the screen select header.php Locate and comment out the line <meta name="viewport" content="width=device-width, initial-scale=1">

Just like so <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->

Save your changes and that's all

I believe this method should work well with any theme. In my case I'm using Astra theme

Upvotes: 0

MattK
MattK

Reputation: 1551

If you are self hosting Wordpress and have Jetpack installed, you may have to disable the mobile theme view by going to:

Jetpack > Settings

Go to the 'Writing' tab and look for 'Optimize your site for smartphones' and disable it there.

This seems to be equivalent to the Settings > Appearance > Mobile Theme switch on wordpress.com.

Upvotes: 3

The Alpha
The Alpha

Reputation: 146191

I think it's better to use a different theme for mobile devices instead of disabling it. In this case there are plenty of plugins in WordPress directory and I personally use and recommend WPtouch because it automatically transforms your WordPress website for mobile devices, complete with ajax loading articles and smooth effects when viewed from popular mobile web browsing devices. If you want to see a preview of WPtouch then you can visit http://heera.it with a mobile phone.

Alternatively, you can use following code (using mobile_device_detect.php script)

include('mobile_device_detect.php');
$mobile = mobile_device_detect();
if ($mobile==true) {
    // do something here, maybe redirect to a page with a message
}

To achieve this, at first you have to get the code from detectmobilebrowsers.mobi and upload it to your theme directory. Once you done, simply open your header.php file and place the code at the top of the file.

Also take a look at this.

Update:

In the accepted answer author mentioned A quick glance at the starkers source makes me think it is not really a mobile component but just a responsive theme. and I've realized that it was a responsive theme but OP didn't mention anything about it in the question and I misunderstood the question and answered. So, as a future reference I didn't delete the answer, keeping on mind that, it could be helpful to others.

This answer could be helpful to those who want to use a different theme for mobile devices.

Upvotes: 0

Ed Burns
Ed Burns

Reputation: 294

If your theme provides mobile detection and a mobile layout which you do not want, first make sure there isn't a theme option to disable it. If there is not, you should be able to remove the mobile detection code by commenting it out and that should do the trick.

The best way to handle mobile theme use is to detect the device and default to the appropriate layout but also provide a user override so they can opt-in to the full site from their phone (or even the mobile site from their desktop). This is done by storing a cookie on the device with the user's choice and using that to override the mobile detection result.

Hmmm. A quick glance at the starkers source makes me think it is not really a mobile component but just a responsive theme. It looks like there is an easy fix though...

Edit parts/shared/html-header.php and remove line 11. It is easy to find because it has a comment that identifies it:

        <meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- Remove if you're not building a responsive site. (But then why would you do such a thing?) -->

It looks like that would remove the responsive behavior of the theme (assuming the comment is correct).

Upvotes: 8

Related Questions