-
AuthorPosts
-
April 9, 2024 at 10:24 am #1439566
Hello,
we use the “Product Grid” element on the homepage. Now it is the case there that if you use the sorting, for example by price, a parameter is appended by Enfold that sorts the products, for example “?avia_extended_shop_select=yes&product_order=price”. In addition, the page is reloaded after the sorting and the user is completely there again at the top of the page. Is there a solution so that after sorting the user is back at the location of the product grid element?
i look forward to hear from you
cheers
Chris
April 12, 2024 at 1:19 am #1439786Hey Chris_85,
Thank you for your patience, when the product filters are used the page is reloaded, this is why the page is then shows at the top, to work around this I would recommend adding this code to the end of your child theme functions.php file in Appearance ▸ Editor:function restore_the_scroll_position_after_reload() { ?> <script> window.addEventListener('beforeunload', function() { localStorage.setItem('scrollPosition', JSON.stringify({ path: window.location.pathname, position: window.scrollY })); }); window.addEventListener('load', function() { const saved = JSON.parse(localStorage.getItem('scrollPosition')); if (saved && saved.path === window.location.pathname) { window.scrollTo(0, saved.position); } }); </script> <?php } add_action( 'wp_footer', 'restore_the_scroll_position_after_reload', 99 );
If you are not using a child theme you could use the WP Code plugin then add a new snippet, in the top right corner use the PHP snippet as the code type:
then add the code and save. Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
Below you can check my test page where I have a large space and then the product grid and when the filter is used and the page is reloaded the page shows at the same place.
But when I test this on your page by injecting it via the browser it seems to work by scrolling back to the correct location after the top of the page is seen. This doesn’t occur on my test page. On your page in the browser console I see the message: Scrolling to section was successful or max attempts reached., this seems to come from a custom javascript file in your child theme: /enfold-child/inc/js/jongo-js.js try disabling the custom this javascript, if you need the custom javascript then perhaps this behavior will be acceptable.Best regards,
MikeApril 12, 2024 at 12:41 pm #1439819thanks! this worked well! Thanks for the good support :-)
April 12, 2024 at 5:31 pm #1439842Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Prevent Scroll to top after Sorting products in Productview’ is closed to new replies.