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('"https://[-_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?
- The topic ‘link rewrite’ is closed to new replies.