user3181912
user3181912

Reputation: 95

Use JS to insert rel=0 into url

I am pulling videos into a WordPress site via a plugin and want to make sure all of the youtube URLs have rel=0 in them to remove the related videos at the end but I am not sure of the best way.

Any ideas?

Upvotes: 0

Views: 150

Answers (1)

n00dl3
n00dl3

Reputation: 21564

This should work :

var parser,iframe;
iframe=$('iframe[src*="youtube.com"]');
parser=document.createElement("a");
iframe.each(function(){
    var $this,search;
    $this=$(this);
    parser.href=$this.attr("src");
    search=parser.search.substr(1);
    search = search.replace(/&?rel=([0-1])/g,'')
    parser.search=search.length>0?search+"&rel=0":"?rel=0"
    $this.attr("src",parser.href);
});

but using php is a better idea

Upvotes: 1

Related Questions