andreint
BuSo Pro
- Joined
- Oct 20, 2014
- Messages
- 167
- Likes
- 241
- Degree
- 1
Hey,
just wanted to leave this script here in case someone finds adding nofollow and target blank attributes to affiliate links time-consuming and frustrating.
This script will automatically make all your outbound links open in a new window + all your Amazon affiliate links will automatically be labeled as nofollow. You can just paste the affiliate link in your content and everything will be handled for you.
Add this to your functions.php file:
just wanted to leave this script here in case someone finds adding nofollow and target blank attributes to affiliate links time-consuming and frustrating.
This script will automatically make all your outbound links open in a new window + all your Amazon affiliate links will automatically be labeled as nofollow. You can just paste the affiliate link in your content and everything will be handled for you.
Add this to your functions.php file:
Code:
function cdx_handel_external_links() {
?>
<script type="text/javascript">
( function( $ ) {
$("a[href^=http]").click(function(){
if(this.href.indexOf(location.hostname) == -1) {
$(this).attr({
target: "_blank"
});
}
})
//Add Nofollow
$("a").each(function(){
if(this.href.indexOf('amazon.com') >0 ){
$(this).attr({
rel: "nofollow"
});
}
});
} )( jQuery );
</script>
<?php
}
add_filter( 'wp_footer', 'cdx_handel_external_links', 999);
Last edited: