Francis Alvin Tan
Francis Alvin Tan

Reputation: 1077

changing a link to a different link using jquery

how to change this URL

<a href="http://mydomain.com/products-page/bath-and-body/">link</a>

to

<a href="http://mydomain.com/bath-and-body/">link</a>

removing the product-page slug from wp e-commerce

so for example there is a link like this

<a href="http://mydomain.com/products-page/bath-and-body/">link</a>

and it will automatically changed to this

<a href="http://mydomain.com/bath-and-body/">link</a>

because I have some links that has a product-page slug and I want to get rid of it, can this be achieved in jquery or php?

Upvotes: 0

Views: 51

Answers (1)

Christopher Armstrong
Christopher Armstrong

Reputation: 7953

PHP:

$link = "http://mydomain.com/products-page/bath-and-body/";
$link = str_replace('products-page/','',$link);

jQuery:

$('a').each(function() {
    $(this).attr('href',$(this).attr('href').replace('products-page/',''));
});

Upvotes: 2

Related Questions