I found this on Stackoverflow: https://stackoverflow.com/questions/21135388/wordpress-change-the-limit-of-the-number-of-posts-just-for-mobile
I implemented the answer, yet it didn't work. I'm working with the AccessPress Mag template, post count on larger screens is set to unlimited.
This is the code I tried:
add_action('pre_get_posts','change_limit_mobile');
function change_limit_mobile($query){
$new_limit = 10;
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
if (( $iphone || $android || $ipad || $ipod || $berry ) && $query->is_main_query()){
set_query_var('posts_per_page',$new_limit);
}
}
I tried adding it to functions.php and the index.php pages, but no luck.
Has anything changed since the latest update, or do I miss something here?