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

TedJonesWeb.blogspot.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com

Popular posts from this blog

Brexit will make Bitcoin more popular

This is why "Credible friends app" is bad - don't use it

"I'm earning 15k and my friends earn 80k", "I feel like I want to end my life."

When you print important crypto stuff (private keys) make sure you use a proper font and don't leave traces on your printer's hard drive and your computer's hard drive

"The Uncensored Hidden Wiki" fake replica!