Skip to content

Instantly share code, notes, and snippets.

@hidrees
Last active April 2, 2022 15:07
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hidrees/76f7c0b3500f8da72ca4 to your computer and use it in GitHub Desktop.
Save hidrees/76f7c0b3500f8da72ca4 to your computer and use it in GitHub Desktop.
Ghost: Open links in new tab
@wstannl
Copy link

wstannl commented Dec 23, 2015

Thank you for the contribution.
Could you please clarify which file by name this is placed and where specifically to place it? Thank you. I have tried ghost.js but it seems to have no effect.

@caroso1222
Copy link

I added this in the index.js file inside the assets/js folder of my theme (casper) and it worked.

@sparlampe1000
Copy link

Works perfectly, thanks a lot!

@DINESHKARPE
Copy link

Works perfectly, thanks

@kirtan403
Copy link

kirtan403 commented Jun 23, 2016

You can directly put this under code injection too between <script> tags.

Copy link

ghost commented May 29, 2017

What must I add to make all external links nofollow?

@Kostanos
Copy link

I like more this one:

<script>
  $(document).ready(function() { 
	$("a[href^='http']").attr("target","_blank");
  });
</script>

Added in the footer of the Code Injection menu in the admin.

As, most of internal link are starting with '/', and they should be opened in the same TAB but, external links starts with http... and it is great to open them in the new TAB

@mhellmeier
Copy link

You could also check this.href.indexOf(window.location.host) == -1 if it is in internal or external link.

See this blog article for more information and a detailed instruction how to use the code in Ghost and another HTML workaround for every post or page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment