Site logo

Archived topic

Smooth Scroll Not Working

7 replies · Started by Annamari on June 9, 2022

Viewing posts 1–8 of 8

Hi,

I'd like to make smooth scroll work on a Woocommerce product page (URL in the private info area below). Clicking on the first button should smooth scroll down to the description part.

I added this code to my child theme's function.php: https://generatepress.com/forums/topic/enable-smooth-scroll-for-all-anchor-links/page/2/#post-827839

Instead of smooth scrolling, I get a question mark in my url...

What can cause this?

Thank you,
Annamari

Hi Leo,

I mean the button to the right of the product image.

Yes, that's the one. I set it up so that it scrolls down to the description part. And it does so, but without smooth scrolling...

What if you try this:

add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
  $elements[] = 'a[href*="#"]:not(.generate-back-to-top)';
  $elements[] = '.single_add_to_cart_button';
  
  return $elements;
} ); 

Thanks, Leo. Still not smooth to me...

Hmm I don't think our smooth scroll script would work in this case unfortunately.

The script requires the a tag with an href link and that is not how the WooCommerce button is constructed:
https://www.screencast.com/t/VDxBvka2

This archived topic is closed to new replies.