WpCode.net

Daily Wordpress Code Snippet

How to Publish Image and description when you use Google Plus

| 0 comments

Pin It

In one of my project i’ve the necessity to publish an item description and a thumbnail when user clicks on Google +1 button; if you use an html5 wordpress theme you could not have to integrate the brand new Google itemprob, but if you use a normal theme you can add this snippet to do what you need. Continue reading

Is the same thing as for the facebook open graph, just add the following code to your function.php theme’s file:

function wpc_plus_itemprop() {
<html itemscope itemtype="http://schema.org/Article">

<!-- Add the following three tags inside head -->
<meta itemprop="name" content="<?php the_title(); ?>">
<meta itemprop="description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>">
<?php $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
		echo '<meta itemprop="image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>'; ?>
<?php }
add_action('wp_head', 'wpc_plus_itemprop');

Leave a Reply

Required fields are marked *.

*