title: What's causing "Cannot read property 'substr' of undefined" error on WordPress using jQuery?
body: <p>I'm listing some user generated links on a page. The problem is that not all users are adding "http://" to their urls, which is messing things up.</p>
  
  <p>In response to this I've used this piece of jQuery ("$" replaced with "jQuery" due to noconflict mode) to try to detect whether http:// is present and add it if it's not:</p>
  
  <pre><code>jQuery('.theirsite').each(function(){
      var currentlink = jQuery(this);
      var linkloc = currentlink.attr('href');
      var httpcheck = linkloc.substr(0,7);
      if(httpcheck!="http://"){
              currentlink.attr('href','http://'+linkloc);
      }
  });
  </code></pre>
  
  <p>But it's not working, and I'm seeing this error in Chrome's console:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'substr' of undefined (index):456
  (anonymous function) (index):456
  x.extend.each jquery.js:3
  x.fn.x.each jquery.js:3
  (anonymous function)
  </code></pre>
  
  <p>This is the php I'm using:
  <code>&lt;div class="theirsite"&gt;&lt;?php echo '&lt;a href="' . $user_info-&gt;user_url . '" class="button"&gt; Visit their website &lt;/a&gt;';?&gt;&lt;/div&gt;</code></p>
  
  <p>The whole thing is on WordPress. Apologies if I've left anything out or not seen anything obvious. All pointers appreciated.</p>