Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created February 7, 2012 01:36
Show Gist options
  • Save GaryJones/1756487 to your computer and use it in GitHub Desktop.
Save GaryJones/1756487 to your computer and use it in GitHub Desktop.
Add pinterest link after each post, only on singles.
<?php
add_action( 'genesis_post_content', 'child_add_pinterest_link', 15 );
/**
* Add pinterest link after post.
*
* Conditionally limited to single post. Remove the first conditional
* to make it show up on archive pages too.
*
* @since 1.0.0
*
* @author Gary Jones
* @link https://gist.github.com/1756487
*/
function child_add_pinterest_link() {
if ( ! is_single() )
return;
// Prepare URL
$url = add_query_arg(
array(
'url' => get_permalink(),
'media' => genesis_get_image( array( 'format' => 'url' ) )
),
'http://pinterest.com/pin/create/button/'
);
// echo markup - be aware that this is invalid markup!
// count-layout can be horizontal, vertical, or none.
echo '<a href="' . esc_url( $url ) . '" class="pin-it-button" count-layout="horizontal">' . __( 'Pin It', 'child-theme-domain' ) . '</a>';
}
add_action( 'wp_enqueue_scripts', 'child_add_pinterest_script' );
/**
* Enqueue script for pinterest pin it button.
*
* Conditionally limited to single post. Remove the first conditional
* to make it show up on archive pages too.
*
* @since 1.0.0
*
* @author Gary Jones
* @link https://gist.github.com/1756487
*/
function child_add_pinterest_script() {
if ( ! is_single() )
return;
wp_enqueue_script( 'pinterest', 'http://assets.pinterest.com/js/pinit.js', false, false, true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment