Skip to content

Snippet: Use Local Scroll for the Top Bar Social Email Link

The following snippet can be used to add the local-scroll-link classname to the top bar email social link so that you can have it local scroll to a section on a page rather then going to a custom url. Note: By default the theme will try and automatically add the local scroll class to links that scroll to parts on the same page, this snippet is only needed when using a full URL for your contact link rather then the contact section ID such as (#contact-section-id).

/**
 * Add local scroll to the top bar social link.
 *
 * @link https://total.wpexplorer.com/docs/snippets/local-scroll-topbar-email/
 **/
add_filter( 'totaltheme/topbar/social/link_attributes', function( $attributes, $site ) {
    if ( 'email' === $site ) {
        $class = $attributes['class'] ?? '';
        $attributes['class'] = trim( $class . ' local-scroll-link' );
        $attributes['target'] = '';
    }
    return $attributes;
}, 10, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top