Good, since it seems that there is no better way at the moment, here is my solution combining JS, PHP and Cookies.
I hope there will be better answers in the future
<?php if( isset($_COOKIE["device_pixel_ratio"]) ){ $is_retina = ( $_COOKIE["device_pixel_ratio"] >= 2 ); if( $is_retina) $thumbnail = get_image( $item_photo, 'thumbnail_retina' ) ; else $thumbnail = get_image( $item_photo, 'thumbnail' ) ; }else{ ?> <script language="javascript"> (function(){ if( document.cookie.indexOf('device_pixel_ratio') == -1 && 'devicePixelRatio' in window && window.devicePixelRatio == 2 ){ var date = new Date(); date.setTime( date.getTime() + 3600000 ); document.cookie = 'device_pixel_ratio=' + window.devicePixelRatio + ';' + ' expires=' + date.toUTCString() +'; path=/'; </script> <?php } ?>
in the .php function:
add_action( 'init', 'CJG_retina' ); function CJG_retina(){ global $is_retina; $is_retina = isset( $_COOKIE["device_pixel_ratio"] ) AND $_COOKIE["device_pixel_ratio"] >= 2; }
Then, after I can use the following GLOBAL:
global $is_retina; or $GLOBALS['is_retina'];
chriscatfr Mar 05 '13 at 21:48 2013-03-05 21:48
source share