Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Add Smooth Scroll effect to site logo

  • Hello,

    I’ve created a one-page website and enabled the smooth scroll effect by adding the .smooth-scroll class. However, I’m having trouble adding this effect to my site logo so that when it’s clicked, it scrolls smoothly to the top. I attempted to add the following code to my functions.php file, but it didn’t work:

    // CHANGE SITE LOGO LINK
    add_filter( 'generate_logo_href', function() {
        return "#";
    } );
    
    // ADD SMOOTH SCROLL CLASS TO SITE LOGO
    add_filter( 'generate_logo_output', function( $output, $logo_url, $html ){
    	$my_search='site-branding-container';
    	$my_new_class='smooth-scroll';
    	$my_replace= $my_search . ' ' . $my_new_class;
    	$new_content = str_replace($my_search, $my_replace, $output);
    	return $new_content;
    } , 10, 3 );
  • Hi there,

    for a one page website then i would not bother with the smooth scroll in the theme.
    Disable that and just add this CSS:

    
    html {
        scroll-behavior: smooth;
    }
    
  • That solved everything. Thank you!

  • Glad to hear that

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.