How to add Reddit button to Blogger (Blogspot) - the problem with country specific domain redirection

The original code is not working because sometimes the user is being redirected to different domain name (for example, if the user is from Finland, the user's browser will be redirected to tedjonesweb.blogspot.fi instead of tedjonesweb.blogspot.com and social network buttons may not work properly).


Also the original code is not useful if user is visiting the homepage of the blog (because the social network is "thinking" that user is willing to "like" or "share" the homepage).

If you want to stop the country specific domain redirection, you can insert this JavaScript:

<script type="text/javascript">
var blog = document.location.hostname;
var slug = document.location.pathname;
var ctld = blog.substr(blog.lastIndexOf("."));
if (ctld != ".com") {
var ncr = "http://" + blog.substr(0, blog.indexOf("."));
ncr += ".blogspot.com/ncr" + slug;
window.location.replace(ncr);
}
</script>


But this will not solve the problem when the user is visiting the homepage of the blog.

The original code:

<script type="text/javascript" src="http://www.reddit.com/static/button/button3.js"></script>

After some modifications:

<link expr:href="data:post.canonicalUrl" id="permalinktothispost"/>
<script type="text/javascript">reddit_url=document.getElementById('permalinktothispost').href;</script>
<script type="text/javascript" src="http://www.reddit.com/static/button/button3.js"></script>

Oops... It is not working properly when user is visiting the homepage...

This is working properly but social button is not shown on the homepage:

<b:if cond='data:post.canonicalUrl == data:blog.canonicalUrl'> 
<link expr:href="data:post.canonicalUrl" id="permalinktothispost"/>
<script type="text/javascript">reddit_url=document.getElementById('permalinktothispost').href;</script>
<script type="text/javascript" src="http://www.reddit.com/static/button/button3.js"></script>
</b:if>

Using getAttribute():

<b:if cond='data:post.canonicalUrl == data:blog.canonicalUrl'> 
<link expr:href="data:post.canonicalUrl" id="permalinktothispost"/>
<script type="text/javascript">reddit_url=document.getElementById('permalinktothispost').getAttribute('href');</script>
<script type="text/javascript" src="http://www.reddit.com/static/button/button3.js"></script>
</b:if>

Also you can insert this code somewhere at the post footer:
<a expr:href="data:post.canonicalUrl">Link to this post (with original blogspot.com domain name).</a>

If you insert this code in the header (between <head> and </head>), the link will point to the canonical URL of the page (this is good for website's search engine ranking - read more here):

<link expr:href="data:blog.canonicalUrl" rel="canonical" />

Read how to fix the Facebook button here:


Comments

Popular posts from this blog

Do not use (only) flash memory (SSD drives, hardware wallets, USB flash drives) for your precious private keys!

Archiving private keys - TLDR version

[fixed] "Evolution is currently offline due to a network outage."

"The Uncensored Hidden Wiki" fake replica!

[ad removed]