views:

126

answers:

2

I need to add a suffix of ?hl=foo to the end of all internal URLs on my site.

Im not sure of the best way to do this because of complications such as...

<a href="http://www.example.com"&gt;My Site</a>
<a target="_blank" href="http://www.example.com"&gt;My Site</a>
<a class="a-class" href="http://www.example.com"&gt;My Site</a>
+1  A: 

PHP

Just create a variable that you echo in the source.

Example:

<?php $my_get = "?hl=foo"; ?>

<a href="http://mysite.com&lt;?=$my_get?&gt;"&gt; Yadda </a>

Using Javascript to change each a's href attribute:

  1. Obtain all the elements ( getElementsByTagName('a') )
  2. Run a foreach loop on them
  3. Within the foreach, concat the existing href (http://mysite.com) and ?hl=f00
Max Felker
I can't do that due to complications with the CMS I'm using. However I can run PHP after the CMS has done it's bit. Such as preg_replace.
Ben Shelock
I hear that. Good luck man!
Max Felker
A: 

Try the output_add_rewrite_var function:

<?php
    ob_start();
    output_add_rewrite_var('hl', 'foo');
?>
<a href="/">My Site</a>
<a target="_blank" href="/">My Site</a>
<a class="a-class" href="/">My Site</a>

But I don’t think it works with absolute URLs.

Gumbo