Jump to content

Change Links on my Website to non-Follow except the internal ones

Recommended Posts

Posted
13 hours ago, Collaborada said:

Does this work, even though I didn't use the amazon block but the gallery section instead. And the script is searching for any link that has "amazon" in it. Can I just leave it like that or should I change the parts up to something like "https://" 
What would be a smart way to do this?

Posted

Hi there. Yes, you need to adjust it for your needs.

Building high-performance websites with expert SEO for local and national reach. Have an SEO question? Google to find our advice or book a Zoom session for tailored help.  Squarespace since 2013 

Posted (edited)

@Collaborada
Any idea how to make the internal links to my pages NOT open up in a new tab. 

 

<script>
  (function () {
    window.addEventListener('load', function () {
      var fixAmazonLinks = function () {
        var amazonLinks = document.querySelectorAll(
          'a[href*="https://"], a[href*="www."]'
        );

        if (!amazonLinks instanceof NodeList) {
          return;
        }

        amazonLinks.forEach(link => {
          link.rel = 'nofollow';
          link.target = '_blank';
        });
      };
      fixAmazonLinks();
    });
  })();
</script>

Edited by wzrdofthestnk
Posted

Hi there. The target="_blank" attribute tells a browser to open a link in a new tab.

Building high-performance websites with expert SEO for local and national reach. Have an SEO question? Google to find our advice or book a Zoom session for tailored help.  Squarespace since 2013 

Posted (edited)
1 hour ago, Collaborada said:

Hi there. The target="_blank" attribute tells a browser to open a link in a new tab.

Thanks, I tried "blank" and "self" both not working for my needs.
I need a solution to make the links that lead to my internal pages open in same tab
and links that lead to external pages open in different tab

Any ideas how I can manage this myself? Thanks

Edit: 
If if disable the "open link in new tab" in the content section of my carousel slides it still opens my internal links in a new tab. Any way I can make this feature usable again?

Might have to do with this code I added to Code Injection -> Footer, that made my images and cards clickable in the carousel sections.



Would really appreciate the help ! 

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
  $( ( ) => {
  
    const selector = '.user-items-list-carousel__slides .list-item';
    
    $( selector ).each ( function ( ) {
    
      const $this = $( this );
      
      $( $this ).click ( function ( ) {
      
      const url = $( '.list-item-content__button', $this )
      
        .attr ( 'href' );
        
      $( `<a href="${ url }" target="_blank">` )
      
      	.get ( 0 )
        
        .click ( );
        
      } );
      
    } );
    
  } );
</script>
<style>
.user-items-list-item-container[data-section-id="6531f15eb6b9412a3a3bb456"] .user-items-list-carousel__slide {
    pointer-events: initial !important;
    user-select: unset !important;
}
.user-items-list-item-container[data-section-id="6531f15eb6b9412a3a3bb456"] .user-items-list-carousel__gutter {
    cursor: pointer;
}
</style>
Edited by wzrdofthestnk
Posted

When you create an internal link you'll want to make sure the toggle for "open link in new tab" is toggled off. It tries to auto-detect external and internal links--but currently, it isn't detecting all internal links. Good luck! 

Building high-performance websites with expert SEO for local and national reach. Have an SEO question? Google to find our advice or book a Zoom session for tailored help.  Squarespace since 2013 

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.