Since I create a lot of tutorials and use GitHub for source control, I embed a lot of gist files to show the code used in my tutorials that include snippets. While the code is displayed in the post, readers often need to view the raw source for easier copying/pasting. In the bottom section of the gist embed, there are a few links, one of them being to the raw source. By default, GitHub does not set these links to open in new tabs. However, many website owners, myself included, prefer to open external links in new tabs or windows to prevent the user from leaving their site.
The following line of jQuery adds the target="_blank"
attribute to all of the links within the gist’s footer/meta area.
You can enqueue this file via the WordPress wp_enqueue_scripts()
function or, if you’re not using WordPress, add it to your site’s footer using your normal method.
Leave a Reply