禁用 wordpress 主题的移动视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14094745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:06:56  来源:igfitidea点击:

Disabling mobile view for wordpress theme

wordpress

提问by Louismoore18

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?

我正在寻找一种在我的 iPhone 上查看我的网站时禁用移动视图的方法。是否有插件或一些代码可以做到这一点?

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

我的主题是 starkers-master 并且没有选择这样做

回答by Ed Burns

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.

处理移动主题使用的最佳方法是检测设备并默认为适当的布局,但还提供用户覆盖,以便他们可以从手机(甚至从桌面上选择移动网站)选择加入完整站点。这是通过在设备上存储用户选择的 cookie 并使用它来覆盖移动检测结果来完成的。

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...

嗯。快速浏览一下 starkers 的源代码让我觉得它并不是一个真正的移动组件,而只是一个响应式主题。不过看起来有一个简单的解决方法......

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

编辑parts/shared/html-header.php并删除第11行。它很容易找到,因为它有一个注释来标识它:

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

看起来这会消除主题的响应行为(假设评论是正确的)。

回答by MattK

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

如果您是自托管 Wordpress 并安装了 Jetpack,则可能需要通过以下方式禁用移动主题视图:

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.

这似乎相当于 wordpress.com 上的“设置”>“外观”>“移动主题”开关。

回答by The Alpha

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 WordPressdirectory and I personally use and recommend WPtouchbecause 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 WPtouchthen you can visit http://heera.itwith a mobile phone.

我认为最好为移动设备使用不同的主题,而不是禁用它。在这种情况下,WordPress目录中有很多插件,我个人使用并推荐WPtouch,因为它会自动将您的 WordPress 网站转换为移动设备,并在从流行的移动 Web 浏览设备查看时完成 ajax 加载文章和流畅的效果。如果您想查看预览,WPtouch则可以http://heera.it使用手机访问。

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

或者,您可以使用以下代码(使用mobile_device_detect.php脚本)

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.mobiand upload it to your theme directory. Once you done, simply open your header.phpfile and place the code at the top of the file.

为此,首先您必须从detectmobilebrowsers.mobi获取代码并将其上传到您的主题目录。完成后,只需打开header.php文件并将代码放在文件顶部。

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 OPdidn'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.

在作者提到的接受的答案中A quick glance at the starkers source makes me think it is not really a mobile component but just a responsive theme.,我意识到这是一个响应式主题,但OP在问题中没有提及任何相关内容,我误解了问题并回答了。因此,作为将来的参考,我没有删除答案,请记住,它可能对其他人有所帮助。

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

这个答案可能对那些想要为移动设备使用不同主题的人有所帮助。