Title: link rewrite
Last modified: August 19, 2016

---

# link rewrite

 *  [mouseclone](https://wordpress.org/support/users/mouseclone/)
 * (@mouseclone)
 * [17 years ago](https://wordpress.org/support/topic/link-rewrite/)
 * I’m looking to rewrite links on my blog that I will be using in the future and
   some in the past. I’m currently using add_fliter(‘the_content’, ‘mouseclone’).
 * This works great for the first link in the post. But if there is more than one
   link in a post, it will only do the first one.
 * `
    36 function mouseclone_links($str) 37 { 38 // find the url 39 $matches = array();
   40 preg_match('"http://[-_a-z0-9.]*mouseclone.com[^"]*"‘,$str,$ma tches); 41 
   42 // loop through the matches 43 if(count($matches) > 0) { 44 foreach($matches
   as $k=>$v) 45 { 46 $replace = ”; 47 if(strpos($v,’?’)) 48 { 49 $replace = substr(
   $v,0,strlen($v)-1).’&pytr=1234″‘; 50 }else{ 51 $replace = substr($v,0,strlen(
   $v)-1).’?pytr=1234″‘; 52 } 53 if(!empty($replace)) 54 { 55 $str = str_replace(
   $v,$replace,$str); 56 } 57 } 58 } 59 60 // return the replaced string 61 return
   $str; 62 }
 * Again. It works, but only does the first link in a post. Is there anyway to get
   it to work on 2 or more links in a post?

Viewing 1 replies (of 1 total)

 *  Thread Starter [mouseclone](https://wordpress.org/support/users/mouseclone/)
 * (@mouseclone)
 * [17 years ago](https://wordpress.org/support/topic/link-rewrite/#post-1030999)
 * Anyone with any ideas?

Viewing 1 replies (of 1 total)

The topic ‘link rewrite’ is closed to new replies.

## Tags

 * [add_filter](https://wordpress.org/support/topic-tag/add_filter/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 1 reply
 * 1 participant
 * Last reply from: [mouseclone](https://wordpress.org/support/users/mouseclone/)
 * Last activity: [17 years ago](https://wordpress.org/support/topic/link-rewrite/#post-1030999)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
