You may find yourself in a situation where you need to add a custom meta tag or Canonical URL to your <head> template, and for any number of reasons, this can't be 'hard coded' into the <head> tag - it needs to be dynamic based on each individual page. Some situations where this might arise are:
- If you want to specify the URL that the OpenGraph URL and/or Shareaholic:url meta tag points to, if it differs from your current permalink. This can be helpful in retrieving shares from different permalink paths.
- You are a marketer or non-Dev using Google Tag Manager, and wish to insert the Shareaholic metatags on your site. This method will allow you to do so without having to contact your development team.
NOTE: If you are using this code snippet on a page where Shareaholic is installed, this code snippet must be included before Shareaholic.js loads on your page, so it must come before your Shareaholic Setup Code.
To set your Shareaholic:URL meta tag instead, simply replace the "og:url" in the snippet above with "shareaholic:url"
If you want to use this code to add the Shareaholic Site ID to your Root Domain for verification purposes, you can modify it as follows:
link.content="[[YOUR SITE ID]]";
To break it down a little, this code first creates a meta tag element, then we specify the name of the meta tag, as well as the content of the meta tag. Finally, we append this newly created meta tag element to your <head> tag on your page, and you're off and running!
Remember: If you are using this code on a page that is also loading Shareaholic, this code snippet must come before the line that loads Shareaholic.js in the header, or else the code snippet will not work.