Jump to content

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

Recommended Posts

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?

Link to comment

@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
Link to comment

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

Have SEO questions? Chances are we've written about it! Try a quick Google search to find our advice. Or for personalized support, see our consulting and training sessions.  Official Squarespace Experts since 2014 

Link to comment
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
Link to comment

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! 

Have SEO questions? Chances are we've written about it! Try a quick Google search to find our advice. Or for personalized support, see our consulting and training sessions.  Official Squarespace Experts since 2014 

Link to comment

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.