Created
January 24, 2018 01:46
-
-
Save wokamoto/9c3bb56bc44c1e02d2e7b5b9ae5fcb07 to your computer and use it in GitHub Desktop.
[WordPress] wp_is_mobile() を CloudFront に対応させる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'wp_is_mobile', function( $is_mobile ) { | |
// CloudFront でスマートフォンと判定された場合、true を返す。 | |
if ( isset($_SERVER['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER']) && "true" === $_SERVER['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] ) { | |
$is_mobile = true; | |
} | |
// CloudFront でタブレットと判定された場合、true を返す。 | |
// (タブレットはPCと同じ扱いにしたい場合は、$is_mobile を false にする | |
if ( isset($_SERVER['HTTP_CLOUDFRONT_IS_TABLET_VIEWER']) && "true" === $_SERVER['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] ) { | |
$is_mobile = true; | |
//$is_mobile = false; // タブレットをPCと同じ扱いにしたい場合は false にする | |
} | |
return $is_mobile; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment