0

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; 
}
?>

1 Answer 1

0

Going by the js you provided you can just do this

if ((screen.width <= 800) && (document.location="https://example.com/")) {
    location.href = "https:example.com/m-home-page/";
}

You could also do this more dynamically using async request but if this solution is enough for you atm then go with it first.

2
  • Hey thanks for the answer unfortunately it didn't work properly I have a feeling there might be something broken on my end. when activated it creates an infinite refresh loop which I can manually stop but it just has a blank screen. I am using buddyboss child theme and injected the code into the custom .js file if that helps.
    – ChrisPy
    Commented Jun 16, 2022 at 21:26
  • Update it does the refresh loop in every page on mobile
    – ChrisPy
    Commented Jun 16, 2022 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.