Easily add a pinterest button to your posts without a plugin

Pinterest_PinIt_Buttons_for_blogger5Adding social links to blog posts sometimes seems like a hassle but actually its not.
Adding it your blog posts is actually quite easy.

There are lots of plugins out there thats does the same but sometimes you want that little extra customization.

The following will be a bit different for  certain cases but this should do the trick in general.
If you want to add it to your actual blog post and not the loop you can simply edit the single.php file in your theme folder.

Find where the loop starts, this will normally begin with

while ( have_posts() ) : the_post();


First we want go the details for the specific post to use in the pin it button.
The Details we need are:
1. The Link to the specific article
2. URL to a media file ( image representing the post )
3. Description for the page ( Optional )

Luckily WordPress provides us with some template tags to easily get these

The link we will get using <?php the_permalink(); ?>.
URL We will grab from the featured Image function WordPress provides.
Description we will grab the Post Title by using <?php get_the_title(); ?>

So right after the loop beginning, add the following between php tags

//Url
$pinterestUrl = the_permalink();

//Image
$image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id() );
$pinterestImg = $image_attributes[0] ;
//Description
$pinterestTitle = get_the_title();

Next you can add the following code in the spot where you want to display the button.

<a href="//pinterest.com/pin/create/button/?url=<?php echo $pinterestUrl ; ?>&media=<?php echo $pinterestImg ; ?>&description=<?php echo $pinterestTitle ; ?>" target="_blank" data-pin-do="buttonPin" data-pin-config="above"><img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" /></a>
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>

And thats it, That should give you a pin it button pinning the current post.

Janes Oosthuizen

Author Janes Oosthuizen

Programmer and Tech Junky from Bloemfontein, South-Africa. I have been programming for 8 years in various languages including ( CSS, HTML, jQuery, PHP, MySQL, Wordpress and many other ).

More posts by Janes Oosthuizen

Join the discussion 2 Comments

  • Harriett says:

    Hey would you mind letting me know which web host you’re utilizing? I’ve
    loaded your blog in 3 completely different web browsers and I must say this blog loads
    a lot quicker then most. Can you recommend a good web hosting provider at a fair price?
    Thank you, I appreciate it!

Leave a Reply