如何在Android应用程序中防止网站页眉和页脚 [英] How to prevent websites header and footer in android app

查看:29
本文介绍了如何在Android应用程序中防止网站页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 WordPress 构建的网站,现在我想制作一个使用该网站的 android 应用程序.我希望页眉/页脚是动态的,如下所示:

I have a website which is built using WordPress, now I want to make an android app which will use this website. I want the header/footer to be dynamic as follows:

User access     | header displayed?
app             | no
android browser | yes

有什么想法或建议怎么做?有没有我可以使用的 WordPress、android 或 JavaScript 插件?

Any idea or suggestions how to do it? Is there any WordPress, android or JavaScript plugin which I can use?

推荐答案

在您的 Android 应用程序的 Web 视图上设置一个 User-Agent,然后检查 WordPress 模板中的 User-Agent 以决定要显示/隐藏的内容.

Set a User-Agent on your web view in your Android app and then check the User-Agent in your WordPress templates to decide what to show/hide.

例如,在您的用户代理中包含 sitename-native-app.这解释了如何在 Android 中设置您的用户代理:android 用户代理

For instance, include sitename-native-app in your User-Agent. This explains how to set your User-Agent in Android: android user agent

在 WordPress 端,创建一个函数来检查用户代理.示例:

On the WordPress side, create a function to check the User Agent. Example:

function is_native_app() {
    return ( false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ), 'sitename-native-app' ) );
}

然后,在包含页眉和页脚的模板中,用以下内容换行:

Then, in your template where you include your header and footer, wrap with:

if ( !is_native_app() ) { ... }

这篇关于如何在Android应用程序中防止网站页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆