WP PostRatings – Rich Snippet Meta with one pager WordPress

wp postratings rich snippet aktivieren

 

I think this won’t be useful for most of you guys, BUT if you’re using WordPress in a way like me, you will be able to implement this tip for your wordpress page!

 

When it’s useful to use this modification

I have some projects where I use WordPress to just make one pager sites.
This means I fix one very long and informational post on starting page and set everything else to noindex so I won’t get duplicate content issues on the website itself.

The problem here is, that WP PostRatings will display the META data for ratings only in the full view of the post not on the starting page where I’d like it to be, cuz my whole website is made up of this one page.

 

How to enable META on start page

You open the WordPress backend. Then you go to Plugins -> WP Postratings and click on edit.
You search now for the word meta backwards in the editor window.

Here you should find the following code:

// Google Rich Snippet
	$ratings_options['richsnippet'] = isset($ratings_options['richsnippet']) ? $ratings_options['richsnippet'] : 1;
	if($ratings_options['richsnippet'] && (is_single() || is_page()) && $is_main_loop && $post_ratings_average > 0)
	{
		if(!isset($post_excerpt))
			$post_excerpt = ratings_post_excerpt($post_id, $post->post_excerpt, $post->post_content, $post->post_password);

		$post_meta = '<meta itemprop="name" content="'.esc_attr($post_title).'" /><meta itemprop="description" content="'.wp_kses($post_excerpt, array()).'" /><meta itemprop="url" content="'.$post_link.'" />';
		$ratings_meta = '<div style="display: none;" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">';
		$ratings_meta .= '<meta itemprop="bestRating" content="'.$ratings_max.'" />';
		$ratings_meta .= '<meta itemprop="ratingValue" content="'.$post_ratings_average.'" />';
		$ratings_meta .= '<meta itemprop="ratingCount" content="'.$post_ratings_users.'" />';
		$ratings_meta .= '</div>';

		$value = $value.$post_meta.$ratings_meta;
	}

 

We only need the topline of this code block:

if($ratings_options['richsnippet'] && (is_single() || is_page()) && $is_main_loop && $post_ratings_average > 0)

Because we will modify this to make the META data show on the front page, where our post is fixed and shown:

if($ratings_options['richsnippet'] && (is_single() || is_page() || is_front_page() ) && $is_main_loop && $post_ratings_average > 0)

Now we have the rating data ready for Google to pickup and show in the SERPs.

 

Don’t forget

To add the following code where the ratingselector + meta data should be shown in your page:

<?php if(function_exists('the_ratings')) { the_ratings(); } ?>

Have fun collecting stars and more traffic :*

Leave a Comment