Facebook, Twitter, and Google +1 buttons using onl

2019-02-08 06:26发布

问题:

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:

  • http://developers.facebook.com/docs/reference/plugins/like/
  • http://twitter.com/about/resources/buttons
  • http://www.google.com/webmasters/+1/button/

回答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:

Facebook

<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>

Twitter

<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>


回答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


回答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

TWITTER

<a href="https://twitter.com/intent/tweet?url=YOURURLHERE&text=YOURPOSTTITLEHERE&via=YOURTWITTERNAMEHERE">Twitter</a>

FACEBOOK

<a href="https://facebook.com/sharer.php?u=YOURURLHERE">Facebook</a>

GOOGLE+

<a href="https://plus.google.com/share?url=YOURURLHERE">Google+</a>