Generated social media links
Use the var keyword to declare titleElement and linkElement in this scope, otherwise they will always be global variables and you'll have no choice about it.

Using var will still put them in the global scope until you wrap this logic in a closure:

(function() {
    // var titleLink...
})();


You should still take the advice of @NebulaFox - don't use document.write.