Add Pinterest and Google+ Sharing to Your Website (w/o Javascript)
For a lot of people this may be common knowledge, but if you are interested in having share “buttons” or “links” for Pinterest and/or Google+, the solution can be a bit hard to find. For pinterest, I found the solution myself, but for Google Plus, I cannot take the credit as it goes to this post.
If you have any questions or want the link format for any other social sharing website post in the comments and I will place it here as well. Here are the solutions.
- Because of Pinterest needing to pull an image for each article or resource that is pinned, you will need to edit your theme so that it supplies your post thumbnail URL. You may already know how to do this on your own, but if not Blogcastor has a great tutorial on how to do so. But I will reiterate it here.
- Open your functions.php file and insert this snippet:
12345678910<?php// Get only the image url link by http://blogcastor.com from http://ajtroxell.comfunction gangmei_get_the_post_thumbnail_url( $post_id = NULL ) {global $id;$post_id = ( NULL === $post_id ) ? $id : $post_id;$src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full');$src = $src[0];return $src;}?> - After saving this, you can now use the following tag to insert the URL of your post thumbnail anywhere in your theme files. You can specify what size variant of your thumbnail you would like to use by changing the text “large” to any other size you have for post thumbnails.
1<?php echo gangmei_get_the_post_thumbnail_url($post->ID, 'large'); ?> - Now you can place the following code in the loop for each post, allowing visitors to pin your posts to Pinterest.
1<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink();?>&media=<?php echo gangmei_get_the_post_thumbnail_url($post->ID, 'large'); ?>&description=<?php echo get_the_excerpt(); ?>" onclick="window.open(this.href); return false;">Pinterest</a> - Your Pinterest share link now contains a link to your article, the link to the image associated with your article, and the excerpt with paragraph tags removed.
Google+
- Up until recently there has been no way of putting a share link for Google+ on your site without using the Javascript version. For many people, including myself, this is a pain because we don’t want visitors to have to rely on Javascript to be able to Plus 1 an article we have written.
- However, now their is a solution. I can’t recall where I initially found this, but you can view another reference to it here.
All you need to include in your theme is this snippet:
1<a href="https://plusone.google.com/_/+1/confirm?hl=en&url=<?php the_permalink();?>">Google +1</a> - Now your visitors can Plus 1 your articles without you having to use Javascript.
Just like any solution, these aren’t necessarily the way these sharing links were intended to be used, without Javascript that is. And chances are most of your visitors have Javascript enabled so you probably wouldn’t run in to any trouble. I however, do not want to use any more Javascript than I have to.
Because of that fact, I have to make some compromises. Any of my share links take my visitors to another page, away from my site, which could hurt my visits a little, since they may share the link and then simply navigate away from and not come back. Yet, I do not have to load the specific Javascript file from each of these services which saves me some load time.
I guess I could have each link load the page in a modal window that is already a component of the Lightbox script that I use. Then I would not be using any more Javascript than I already do, but it would be a cleaner solution and keep visitors on the site. I see another article coming!