I have seen many like this question (like How to redirect non-logged in users to a specific page?) but none have worked.
this is basically what I've come up with but it doesn't work all the time and has a refresh loop afterwards.
if ((screen.width <= 800) && (document.location="https://example.com/")) {
window.location.replace = "https:example.com/m-home-page/";
window.location.reload();
}
This is a php I was testing as well which redirected the blog page to the home page for some reason. (from https://stackoverflow.com/questions/39438523/how-to-redirect-logged-out-users-to-different-page-in-wordpress)
<?php
if(is_user_logged_in())
{
wp_redirect( home_url('/m-home-pages') ); // This will redirect to the home page which we have created.
exit;
}
else
{
wp_redirect( home_url() );// this will redirect to the site main home page.
exit;
}
?>