Shortcode: Add Pinterest “Pin it” button to your posts

Pinterest is a Virtual Pinboard. It lets you organize and share all the beautiful things you find on the web. People use pinboards to plan their weddings, decorate their homes, and organize their favorite recipes. Best of all, you can browse pinboards created by other people. Browsing pinboards is a fun way to discover new things and get inspiration from people who share your interests.

This post is about how you can let your visitors pin your posts to their Pinterest boards.

Add following snippet in your functions.php


add_shortcode('pin_it', 'wpds_pin_it');
function wpds_pin_it( $atts, $content=null ){
    global $post;
        'url' => null,
		'button_layout'=>'vertical' // vertical, horizontal, none
    ), $atts));

	if(empty($img_url)) {
		$img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
		$img_url = $img[0];
		$title = get_the_title();
		$url = get_permalink($post->ID);

	$output = '<a href="' . urlencode($url) . 
				'&media=' . $img_url . '&description=' . get_the_title() .'" '.
				'class="pin-it-button" count-layout="vertical">Pin It</a>';

    return $output;
function enqueue_pinterest_script(){

2 Responses to Shortcode: Add Pinterest “Pin it” button to your posts

  1. I like the valuable info you provide on your articles.
    I’ll bookmark your blog and test once more here frequently. I’m relatively sure I will be
    informed lots of new stuff right right here! Good luck for
    the following!

  2. Oh my goodness! Incredible article dude!
    Thank you so much, However I am experiencing troubles with your RSS.

    I don’t know the reason why I can’t subscribe to it. Is there anybody having
    identical RSS issues? Anybody who knows the solution will you kindly respond?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>