Archived topic
Enable Smooth Scroll on buttons
9 replies · Started by Daniele on March 27, 2019
Hi, how can I enable smooth scroll on buttons on my website. I can add classes to button, but "a" tag is inside the button so I cannot put smoot-scroll class directly on "a" tag.
Example:
<div class="wp-block-button is-style-squared smooth-scroll">
<a href="#contact-form">CHIEDI INFORMAZIONI</a></div>
Hi there,
yes the button block is a bit of a pain for adding the wrapper to the button. There is this PHP snippet that applies the smooth-scroll to all tags:
https://docs.generatepress.com/article/generate_smooth_scroll_elements/
THANKS
You're welcome
Hello,
I'm unable to get smooth-scroll to enable on a button in my hero.
I've ticked the enable smooth-scroll box.
My button looks like this:
<p><a class="button smooth-scroll" href="#consult">Call to Action</a></p>
And I've added and enabled the recommended PHP snippet:
add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
$elements[] = 'a[href*="#"]';
return $elements;
} );
And still I get no smooth-scroll effect with my button. Any suggestions?
The link you provided in the original topic isn't working for me.
Can you confirm and maybe update that?
Let me know :)
Hi Leo,
I edited my original comment after posting it because of a typo. The link should say "#consult". The link works on my website currently - just with no smooth-scroll effect. Does it work for you?
I just can't get the site to load at all - it says This site can't be reached
Is that still the correct URL?
Oh, my mistake. I am not the original poster - I just have a similar problem. My website is [removed]
Ahh Daniele and Daniel haha
In that case can you please open a new topic?
Thanks :)