Altering all urls to include extra information
So you're looking for a way to modify a link URL as it is being written? I looked into this recently and was surprised at how much hunting was required.

I went with hook_url_outbound_alter( &amp;$path, &amp;$options, $original_path ), which allows you to alter link URLs that are being written by the Drupal URL system. 

There's also hook_url_inbound_alter( &amp;$path, $original_path, $path_language ), which might be better as it includes the path's specific langauge - it depends on where you want the alteration to take place. I personally find hook_url_outbound_alter() reliable and simple to work with - it changes all appropriate URLs as they are written, and using $options you can reliably add and edit query strings (...?query=string&amp;foo=bar) and hash frangments (...#someId).

Modify $path and it'll update the actual path that gets written into the URL href. Of course, this runs on all links, so you'll want to start by checking that it's a link you want to modify. 

It's executed before aliasing, so it'll be based on the Drupal defaults. To give two very simplistic examples, if you want to modify only taxonomy paths:

function some_module_url_outbound_alter( &amp;$path, &amp;$options, $original_path ) {
  if(strpos($original_path, 'taxonomy/term') === 0) {
    // do stuff
  }
}


And/or if you only want it to run on particular pages, e.g. node edit pages:

function some_module_url_outbound_alter( &amp;$path, &amp;$options, $original_path ) {
  $current_path = explode("/", current_path() );
  if (count($current_path) &gt;= 3 &amp;&amp; $current_path[0] == "node" &amp;&amp; $current_path[2] == "edit") {
    // do stuff
  }
}