Site logo

Archived topic

Smooth Scrool issue

5 replies · Started by Halil on January 27, 2023

Viewing posts 1–6 of 6

Hi,
I added the snippet below, I took it from here https://docs.generatepress.com/article/generate_smooth_scroll_elements/


add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
  $elements[] = 'a[href*="#"]';
  
  return $elements;
} );

Smooth scrool was not working in TOC block, adding the above snippet solved the issue however this time, it caused another issue, "Load More" button takes you to the top of the site, instead of showing more blog posts.

How can I solve this, could you pls help?

Hi Halil,

Can you try modifying the code to this:

add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
  $elements[] = 'a[href*="#"]:not(.load-more > .button)';
  
  return $elements;
} );

perfect, thanks Ying 👍

No Problem, glad to help :)

Felt important to share this tiny snippet of CSS for folks still struggling with smooth-scroll...

I could not get smooth scroll to work with the default theme settings, or specifying the special class, on buttons. I didn't want to edit php files because it seemed like overkill, nor I wasn't looking for class filtering. I just wanted SMOOTH SCROLLING on tap for any anchor link, button, or div on the website.

In your "Additional CSS" simply add the snippet below. View source on Chrome dev tools and inspect the white hero button at https://webassistant.me/.

html {
  scroll-behavior: smooth;
}

Thank you Jason for sharing this :)

This archived topic is closed to new replies.