简体   繁体   English

如何在Android应用中防止网站的页眉和页脚

[英]How to prevent websites header and footer in android app

I have a website which is built using WordPress, now I want to make an android app which will use this website. 我有一个使用WordPress构建的网站,现在我想制作一个将使用此网站的android应用。 I want the header/footer to be dynamic as follows: 我希望页眉/页脚是动态的,如下所示:

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

Any idea or suggestions how to do it? 有什么想法或建议怎么做? Is there any WordPress, android or JavaScript plugin which I can use? 我可以使用任何WordPress,Android或JavaScript插件吗?

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. 在Android应用程序的网络视图中设置一个User-Agent,然后在WordPress模板中检查User-Agent,以确定要显示/隐藏的内容。

For instance, include sitename-native-app in your User-Agent. 例如,在您的User-Agent中包括sitename-native-app This explains how to set your User-Agent in Android: android user agent 这说明了如何在Android中设置您的User-Agent: android用户代理

On the WordPress side, create a function to check the User Agent. 在WordPress上,创建一个功能来检查用户代理。 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() ) { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM