• Resolved ddmccaleb

    (@ddmccaleb)


    I would like to create a link within my blog that would scroll to the Share section. I do not see a means of inserting an anchor ID to which I could scroll. Any suggestions? I’d very much like to do this to the Follow section as well, which is on the side of the blog post and managed through the Widgets area. Many thanks!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author micropat

    (@micropat)

    Hi David, it looks like you already found that AddToAny’s Sharing Header accepts HTML for your purpose.

    As for your Follow On section, WordPress widget titles don’t allow HTML by default, so you could add some PHP code to your functions.php (or using a functionality plugin like Code Snippets):

    add_filter( 'dynamic_sidebar_params', function( $params ) {
    	// If the widget is named "AddToAny Follow"
    	if ( isset( $params[0]['widget_name'] ) && 'AddToAny Follow' === $params[0]['widget_name'] ) {
    		// Prepend an anchor to the widget
    		$params[0]['before_widget'] = '<a id="follow"></a>';
    		// Just once to avoid potential duplicate anchor IDs on the same page
    		return $params;
    	}
    	return $params;
    } );
    Thread Starter ddmccaleb

    (@ddmccaleb)

    Thank you @micropat ! I have Code Snippets installed and your code works great. I mis-copied it first, but now seems to be working fine. Thanks again!!!

    • This reply was modified 7 months, 2 weeks ago by ddmccaleb.
    Thread Starter ddmccaleb

    (@ddmccaleb)

    In case anyone else has this same question in the future, I adjusted the code just a little to account for scroll offset due to a top navigation bar on my site. It works well on desktop, but doesn’t quite work right on mobile. Maybe @micropat or someone else could help tweak this a bit further if they feel inclined. Thanks!

    add_filter( 'dynamic_sidebar_params', function( $params ) {
    	// If the widget is named "AddToAny Follow"
    	if ( isset( $params[0]['widget_name'] ) && 'AddToAny Follow' === $params[0]['widget_name'] ) {
    		// Prepend an anchor to the widget
    		$params[0]['before_widget'] = '<a id="follow" style="padding-top: 80px;margin-top: -80px"><br></a>';
    		// Just once to avoid potential duplicate anchor IDs on the same page
    		return $params;
    	}
    	return $params;
    } );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘anchors for Share and Follow’ is closed to new replies.