Facebook, Twitter, and Google +1 buttons using only HTML (No Javascript)
Solution 1
The following links will register the appropriate Likes, Tweets and +1s:
- http://www.facebook.com/sharer.php?u=http://example.com
- http://twitter.com/share?url=http://example.com&text=Description
- https://plusone.google.com/_/+1/confirm?hl=en&url=http://example.com
These links will work for Wordpress:
<a href="http://www.facebook.com/sharer.php?u=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank" title="Share this page on Facebook">Like</a>
<a href="http://twitter.com/share?url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>&text=<?php the_title(); ?>" target="_blank" title="Tweet this page on Twitter">Tweet</a>
Google +1
<a href="https://plusone.google.com/_/+1/confirm?hl=en&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank" title="Plus one this page on Google">+1</a>
Solution 2
google plus not working in the above example.
I used this for google plus.
<div id="custom-google-button">
<a href="https://plus.google.com/share?&hl=en&url=YOUR_URL_to_share" target="_blank">google+</a>
</div>
In Wordpress :
<a href="https://plus.google.com/share?hl=en&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank" title="Plus one this page on Google">google+</a>
Linkedin :
<div id="custom-linkedin-button">
<a href="http://www.linkedin.com/shareArticle?mini=true&url=YOUR_URL_to_share" target="_blank">Linkedin</a>
</div>
In Wordpress :
<a href="http://www.linkedin.com/shareArticle?mini=true&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank">Linkedin</a>
Sources :
- https://developers.google.com/+/plugins/share/
- https://developer.linkedin.com/documents/share-linkedin
Solution 3
This is a pretty useful article that provides the answer you are looking for without using any PHP - http://www.hanselman.com/blog/AddSocialSharingLinksToYourBlogWithoutWidgetJavaScript.aspx
<a href="https://twitter.com/intent/tweet?url=YOURURLHERE&text=YOURPOSTTITLEHERE&via=YOURTWITTERNAMEHERE">Twitter</a>
<a href="https://facebook.com/sharer.php?u=YOURURLHERE">Facebook</a>
GOOGLE+
<a href="https://plus.google.com/share?url=YOURURLHERE">Google+</a>
Andrew Odri
Personal social media: https://github.com/andrewodri https://plus.google.com/+andrewodri http://www.linkedin.com/in/andrewodri Company social media: https://github.com/affirmix https://www.npmjs.com/~affirmix https://instagram.com/affirmix https://plus.google.com/+affirmix https://www.linkedin.com/company/affirmix
Updated on April 26, 2020Comments
-
Andrew Odri about 4 years
I would like to know if there is a method to create "share" buttons for Facebook, Twitter and Google +1 using only HTML, without any Javascript having to be inserted into the code at any point.
For example, you can use the methods described below to create these buttons dynamically; however they all end up loading Javascript dynamically and creating their own code behind the scenes:
-
henrywright almost 10 yearsDoes the Facebook url take any more params? Or is it just
u
? -
Andrew Odri almost 10 years@henrywright It seems Facebook now prefers a different syntax; the URL in the answer strill works, but here is more information on how to do this using the share dialog: developers.facebook.com/docs/sharing/reference/… Regarding options for the legacy URL, see this post: ar.zu.my/…