Skip to main content

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

$pinterestUrl = the_permalink();

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

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

<a href="//<?php echo $pinterestUrl ; ?>&media=<?php echo $pinterestImg ; ?>&description=<?php echo $pinterestTitle ; ?>" target="_blank" data-pin-do="buttonPin" data-pin-config="above"><img src="//" /></a>
<script type="text/javascript" src="//"></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 Cape Town, South-Africa. I have been programming for more than 15 years in various languages including ( CSS, HTML, javascript, 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