title: jQuery/Drupal Append string to all HREF on site (Any page)
body: <p>So I have a site with a dozen pages on it using Drupal as a CMS. Wanted to know how to set/append all href links on any page with a dynamic attribute?</p>
  
  <p>so here is an example URL:</p>
  
  <pre><code>http://www.site.com/?q=node/4
  </code></pre>
  
  <p>and I wanted to append to the URL like so:</p>
  
  <pre><code>http://www.site.com/?q=node/4&amp;attr=1234
  </code></pre>
  
  <p>Now I have a nav bar on the site and when I hover over the link I see the url but I need to append the &amp;attr=1234 string to the end of it. The string is dynamic so it might change from time to time.</p>
  
  <p>I was thinking jQuery would be a good choice to do this but does Drupal have any functionality as well?</p>
  
  <p>Now I've seen a couple of posts on Stack:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2866341/jquery-replace-contents-of-href-with">Post 1</a></li>
  <li><a href="https://stackoverflow.com/questions/179713/how-to-change-the-href-for-a-hyperlink-using-jquery">Post 2</a></li>
  </ul>
  
  <p>Problem is I'm learning my way around Drupal and have minimal experience with jQuery but getting better with both. I see the jQuery can replace a HREF but looks like they hard coded the HREF, could jQuery find all HREF's on a page and append the string to it? Also does Drupal have this functionality and what would be the best approach?</p>
  
  <p>Also need this to work for clean or standard URL format, so I think Apache would handle this I just wanted to make sure.</p>
  
  <p>Thanks for any help</p>
  
  <p>EDIT:</p>
  
  <p>Looks like the general consensus is the Drupal should handle this type of request. Just looking for the best implementation. Simple function call would be best but I would like it to dynamically add it to all existing href's as I want this to be dynamic instead of hard coding any url/href calls. So I could add/remove pages on the fly without the need to reconfigure/recode anything.</p>
  
  <p>Thanks for the great tips though </p>
  
  <p>EDIT #2:</p>
  
  <p>Okay maybe I'm asking the wring question. Here is what I need and why it's not working for me yet.</p>
  
  <p>I need to pass a value in the url that changes some of the look and feel of the site. I need it to be passed on just about every href tag on the page but not on User logout or Admin pages.</p>
  
  <p>I see in my template code where the nav links get generated, so I though I could pass my code in the attributes array as the second parm to the function, but that is setting the tag attributes and not the URL attributes.</p>
  
  <p>Now I see the bottom nav links use this Drupal function: menu_navigation_links() in menu.inc but the top nav uses a custom function. </p>
  
  <p>This function in the template.php script looks to be the one creating the links</p>
  
  <pre><code>function lplus($text, $path, $options = array()) {
    global $language;
  
    // Merge in defaults.
    $options += array(
        'attributes' =&gt; array(),
        'html' =&gt; FALSE,
      );
  
    // Append active class.
    if (($path == $_GET['q'] || ($path == '&lt;front&gt;' &amp;&amp; drupal_is_front_page())) &amp;&amp;
        (empty($options['language']) || $options['language']-&gt;language == $language-&gt;language)) {
      if (isset($options['attributes']['class'])) {
        $options['attributes']['class'] .= ' active';
      }
      else {
        $options['attributes']['class'] = 'active';
      }
    }
  
    // Remove all HTML and PHP tags from a tooltip. For best performance, we act only
    // if a quick strpos() pre-check gave a suspicion (because strip_tags() is expensive).
    if (isset($options['attributes']['title']) &amp;&amp; strpos($options['attributes']['title'], '&lt;') !== FALSE) {
      $options['attributes']['title'] = strip_tags($options['attributes']['title']);
    }
  
    return '&lt;a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'&gt;&lt;b&gt;'. ($options['html'] ? $text : check_plain($text)) .'&lt;/b&gt;&lt;/a&gt;';
  }
  </code></pre>
  
  <p>not sure how to incorporate what I need into this function.</p>
  
  <p>So on the home page the ?q=node/ is missing and if I append the ampersand it throws an error.</p>
  
  <pre><code>http://www.site.com/&amp;attr=1234 // throws error
  </code></pre>
  
  <p>But if I mod it to the correct format it works fine</p>
  
  <pre><code>http://www.site.com/?attr=1234
  </code></pre>