I am using WPscript and I want to limit the number of posts for the mobile version of the website.
So far I found this code and placed it in the functions.php file. It doesn't do anything, I think it should be placed elsewhere. Any ideas?
Code:
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);
}
}