Tagged: the-events-calendar-pro
-
AuthorPosts
-
June 18, 2024 at 12:48 pm #1451858
Hi there,
please have a look at the website in private content. The links on the calendar pagination (page number or next/previous button) are causing an auto scroll to top. So the user has to scroll down to get to the events again. Is there any chance to prevent that auto scroll.
I already had the people at the Events Calendar support have a look at the issue, but the issue seems unlikely to be coming from them.
Thanks in advance!
Best regards
MarcoJune 22, 2024 at 3:20 pm #1455356Hey Marco,
Thank you for your patience and the link to your page, when the tribe event pagination is clicked the page reloads with the new content, this is why the page shows at the top like any new page would when you use a link to a different page.
To get the scroll position when the pagination button is clicked and then after the page reloads go back to that position add this code to the end of your child theme functions.php file in Appearance ▸ Editor:function adjust_scroll_position_when_tribe_events_pagination_is_used() { ?> <script> document.addEventListener('DOMContentLoaded', function () { function storeScrollPosition() { localStorage.setItem('scrollPosition', window.scrollY); } function scrollToStoredPosition() { const scrollPosition = localStorage.getItem('scrollPosition'); if (scrollPosition) { window.scrollTo({ top: parseInt(scrollPosition, 10), behavior: 'smooth' }); localStorage.removeItem('scrollPosition'); } } const paginationLinks = document.querySelectorAll('.pagination-tribe_events a'); paginationLinks.forEach(link => { link.addEventListener('click', storeScrollPosition); }); scrollToStoredPosition(); }); </script> <?php } add_action( 'wp_footer', 'adjust_scroll_position_when_tribe_events_pagination_is_used', 99 );
Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
Best regards,
MikeJune 24, 2024 at 1:05 pm #1458016Hi Mike,
thanks a lot! Works like a charm. Awesome support as always!
Feel free to close the topic.
Greets
MarcoJune 24, 2024 at 4:33 pm #1458306Hi,
Great, I’m glad that Mike could help you out. Please open a new thread if you should have any further questions or problems.
Best regards,
Rikard -
AuthorPosts
- The topic ‘The Events Calendar Pro – prevent auto scroll to top’ is closed to new replies.