---
title: Detect and handle User-Agent with WordPress and CloudFront
description: CloudFront is great out of the box, but there is a feature common to WordPress that it does not natively support. That feature is wp_is_mobile(), and it's great for creating custom conditionals or con
---

[Skip to content](https://knowledge.amimoto-ami.com/en/knowledge/detect-and-handle-user-agent-with-wordpress-and-cloudfront#main-content)

- [English](https://knowledge.amimoto-ami.com/en/knowledge/detect-and-handle-user-agent-with-wordpress-and-cloudfront)
- [日本語](https://knowledge.amimoto-ami.com/knowledge/self-user-agent-under-cloudfront)

English

Show submenu for translations

![Amimoto-dark-ogp.png\]](https://knowledge.amimoto-ami.com/hs-fs/hubfs/Amimoto-dark-ogp.png?height=40&name=Amimoto-dark-ogp.png)

- ホーム
- 製品
- 価格
- ブログ
- 会社

Open main navigation

Close main navigation

- ホーム
- 製品
- 価格
- ブログ
- 会社
- - [English](https://knowledge.amimoto-ami.com/en/knowledge/detect-and-handle-user-agent-with-wordpress-and-cloudfront)
    - [日本語](https://knowledge.amimoto-ami.com/knowledge/self-user-agent-under-cloudfront)

  English
  
  Show submenu for translations
- [https://amimoto-ami.com/](https://amimoto-ami.com/)

[https://amimoto-ami.com/](https://amimoto-ami.com/)

 Hello. How can we help you?

- There are no suggestions because the search field is empty.

1. [Amimoto Help Center](https://knowledge.amimoto-ami.com/en/knowledge?hsLang=en)
2. [Amimoto AMI](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en)
3. [Tips](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#tips)

# Detect and handle User-Agent with WordPress and CloudFront

CloudFront is great out of the box, but there is a feature common to WordPress that it does not natively support.

That feature is wp\_is\_mobile(), and it's great for creating custom conditionals or content that only display or does not display on mobile.

The catch is that CloudFront does not send User-Agent header info to the origin server. However, you can employ the following solutions to identify mobile browsers' User Agent with CloudFront.

1. Install and activate Nginx Mobile Theme
2. Use wp\_is\_mobile() alt functions

 

### Install and activate Nginx Mobile Theme

This plugin allows you to switch theme according to the User-Agent on the NGINX reverse proxy and enable you to handle header data sent from CloudFront. To enable this feature, install and activate the plugin.

For more details, please check [Configuration on Nginx Mobile Theme](https://knowledge.amimoto-ami.com/en/knowledge/installing-nginx-cache-controller-plugin?hsLang=en).  
 

### Use wp\_is\_mobile() alternative

Add the following code to functions.php in the theme directory to create the wp\_is\_mobile() alternative function.

CloudFront sends  CloudFront-Is-Mobile-Viewer header data to the origin server if a smartphone has accessed it. These codes can detect it and handle it.

```
function cf_is_mobile() {    $is_mobile = function_exists('wp_is_mobile') && WordPress_is_mobile();    // returns true if the CloudFront assumes the browser is  smartphone    if ( isset($_SERVER['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER']) && "true" === $_SERVER['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] ) {        $is_mobile = true;    }    // returns true if the CloudFront assumes the browser is a tablet.    // remove the following three lines to assume table as PC.    if ( isset($_SERVER['HTTP_CLOUDFRONT_IS_TABLET_VIEWER']) && "true" === $_SERVER['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] ) {        $is_mobile = true;    }    return $is_mobile;}
```

#### Further Reading

For more info on wp\_is\_mobile(), check out the WordPress Codex.

[Codex](https://codex.wordpress.org/Function_Reference/wp_is_mobile)

 

 

- [Amimoto Managed Hosting](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#main-content)

    - [Basics](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#basics)
    - [Amimoto Essential Training](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#amimoto-essential-training)
    - [Migration tips for AMIMOTO Managed Hosting](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#migration-tips-for-amimoto-managed-hosting)
    - [Amimoto Dashboard Tips](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#amimoto-dashboard-tips)
    - [Connecting to the Server](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#connecting-to-the-server)
    - [Account and Billing](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#account-and-billing)
    - [Trouble shooting](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#trouble-shooting)
    - [WordPress Plugins](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#wordpress-plugins)
    - [Tips for DNS Vendors](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#tips-for-dns-vendors)
    - [Email](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#email)
    - [CDN and Cache control](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#cdn-and-cache-control)
    - [Server & AWS Management](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#server-aws-management)
    - [Integration](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#integration)
    - [Development](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-managed-hosting?hsLang=en#development)
- [Amimoto AMI](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#main-content)

    - [Getting Started with Amimoto-AMI](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#getting-started-with-amimoto-ami)
    - [Basics](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#basics)
    - [Connection to Amimoto AMI](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#connection-to-amimoto-ami)
    - [Tips](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#tips)
    - [FAQs](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#faqs)
    - [Trouble shooting](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#trouble-shooting)
    - [Getting Started with Amimoto JIN-KEI](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#getting-started-with-amimoto-jin-kei)
    - [Tips for JINKEI](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#tips-for-jinkei)
    - [Support](https://knowledge.amimoto-ami.com/en/knowledge/amimoto-ami?hsLang=en#support)
- [\[EN\] Amimoto Managed Hosting](https://knowledge.amimoto-ami.com/en/knowledge/en-amimoto-managed-hosting?hsLang=en#main-content)

    - [Company and Guidelines](https://knowledge.amimoto-ami.com/en/knowledge/en-amimoto-managed-hosting?hsLang=en#company-and-guidelines)

- ホーム
- 製品
- 価格
- ブログ
- 会社

[![Chill listening crop-3](https://knowledge.amimoto-ami.com/hs-fs/hubfs/Amimoto_Logomark_rgb.png?width=24&height=24&name=Amimoto_Logomark_rgb.png "Chill listening crop-3")](https://ja.amimoto-ami.com/)

Amimoto Help Center

<https://www.facebook.com/AmimotoAMI/> <https://twitter.com/Amimoto_Ami>

Copyright © 2026, 株式会社デジタルキューブ