Skip to content

Instantly share code, notes, and snippets.

@stemar
Last active January 18, 2024 10:50
Show Gist options
  • Save stemar/327e34a0b2bebd11adb5 to your computer and use it in GitHub Desktop.
Save stemar/327e34a0b2bebd11adb5 to your computer and use it in GitHub Desktop.
Adding target="_blank" or any other attribute to a Markdown link
Markdown:
[JP Markdown](https://wordpress.org/plugins/jetpack-markdown){.target-blank .rel-nofollow}
JavaScript (just before the closing </body> tag):
<script>
jQuery('.target-blank').attr('target', '_blank').removeClass('target-blank').filter('[title=""]').removeAttr('title').filter('[class=""]').removeAttr('class');
jQuery('.rel-nofollow').attr('rel', 'nofollow').removeClass('rel-nofollow').filter('[title=""]').removeAttr('title').filter('[class=""]').removeAttr('class');
</script>
Post-jQuery HTML:
<a href="https://wordpress.org/plugins/jetpack-markdown" target="_blank" rel="nofollow">JP Markdown</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment