Autorefresh sends the site to homepage

I love the way this plugin works, and I have placed it on my site. My problem is that when using [app_services autorefresh="1"] the site refreshes and loads it all the way to the top of the page. The site is a one page template with a menu that anchors pages, is it possible that it autorefreshes and comes back to #pricing rather than the top of home? (If I remove autorefresh, clicking the button does the same)

  • Ivan

    Hey there Maria,

    Hope you are having great week so far!

    You could redirect the users with the code provided in the FAQ for Appointments+:

    function app_redirect( $script ){
        return str_replace("window.location.href=app_location()", "window.location.href='http://example.com'", $script);
    }
    add_filter( 'app_footer_scripts', 'app_redirect' );

    You will need to add this to the functions.php of your theme, and change the url to some with anchor, like
    http://example.com/#pricing

    Still I am not sure how your theme will handle this, and how it will behave. Even with this code, it might not work as one page templates are sometimes tricky.

    Let me know if this helps.

    Thanks,
    Ivan

  • Maria

    Hi Ivan thank you so much! After I posted this I actually found someone else who had asked the same question (with better wording and appropriate terms) and they suggested a jquery solution here https://premium.wpmudev.org/forums/topic/jump-to-specific-anchor-after-autorefresh
    And after a little fumbling about I managed to get it to work... (don't ask me how exactly :S) do you think that is a good way to solve this or should I undo and try your way for best results? Thank you again!

  • Maria

    Hi aristhat, thank you for your reply. I've tried both solutions but unfortunately it doesn't work, I guess it has to do with my theme (?) the other solution helped, at least it sort of works but its not as elegant looking as I would like, since it refreshes to the top and scrolls down quite a bit to the previous point, it seems overall confusing and when people get refreshed to the top before it scrolls down and they scroll then it stops working. It works for now while I finish the site, and it would be better if I could do without a refresh altogether, but I think in the long run it won't work for us and forced to chose between the appointments up and the theme i'm affraid the company will prefer the theme (they love how it looks) I'll keep working on it and see if I can figure something out. Thank you for your interest.

  • Vinod Dalvi

    Hi @Maria,

    the other solution helped, at least it sort of works but its not as elegant looking as I would like, since it refreshes to the top and scrolls down quite a bit to the previous point, it seems overall confusing and when people get refreshed to the top before it scrolls down and they scroll then it stops working.

    It depends on how you have implemented/used the provided solution so could you please tell us how you have implemented it and if you can also share the page URL where you are using it so that we can troubleshoot it?

    Regards,
    Vinod Dalvi

  • Maria

    Hi Vinod,
    I'm sorry I didnt get back earlier, the notification got filtered out of my inbox. It is actually working great now, i figured out that if I do what the other user recommended but reduce the scroll time to under a second it just blinks upon refresh and it looks perfect! I'm super grateful of all your help and advice and if it's not too much trouble, one last question, how can I set up that when people click on the confirm or cancel button it takes them again to the same page and not the top? It was working like that a while back but with all the fidgeting I did to sort the refresh out I broke it. Thanks!

  • Maria

    Hi,
    Sure. What I did was follow the advice of the other post and pasted this into my theme's main.js :

    if(window.location.href.indexOf("app_service_id") > -1) {
    jQuery('html,body').animate({scrollTop: jQuery('#pricing').offset().top}, 10);
    }

    Now when I change the service, it auto refreshes and gives a tiny blink and we are exactly where we were before changing. Much better user experience. Now what I want is that when the person either confirms or cancels an appointment, the page doesn't load to the top again, but refreshes on the same anchor.
    my site is at
    http://grupoimd.com.co/wp/
    It is however, all in spanish.

    Thanks

  • Ash

    Hello @Maria

    I hope you are well today.

    Please try the following code:

    function app_redirect( $script ){
        return str_replace("window.location.href=app_location()", "window.location.href='http://grupoimd.com.co/'", $script);
    }
    add_filter( 'app_footer_scripts', 'app_redirect' );

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.