Filters

Filters

rating_form_microdata

Add your own rich snippet schema. For example I have created markup for products. Add the following code in your theme functions.php.

/**
 * Replaces the default markup (http://schema.org/Article) for all rating forms
 * 
 * @param $microdata - Default markup
 * @param $rating_form_info - Array. Contains: average_rating, max_rating, count
 * @param $post_id - Post ID
 * @return data
 */
function rf_product_microdata( $microdata, $rating_form_info, $post_id) {

    // Post Information
    $post_info = get_post( $post_id );
    // Post Image
    $post_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_info->ID ), 'full' );

    // Itemprops
    $microdata = '<meta itemprop="name" content="' . $post_info->post_title . '" />'; // Prost Title
    $microdata .= '<meta itemprop="image" content="' . $post_image[0] . '" />'; // Post featured image (first image)

    // Offer
    $microdata .= '<div style="display: none;" itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">';
    $microdata .= '<meta itemprop="price" content="0" />'; // Price set to zero, meaning free
    $microdata .= '<meta itemprop="priceCurrency" content="USD" />';
    $microdata .= '</div>';

    // AggregateRating
    $microdata .= '<div style="display: none;" itemprop="aggregateRating" itemscope="" itemtype="http://schema.org/AggregateRating">';
    $microdata .= '<meta itemprop="ratingValue" content="' . $rating_form_info['average_rating'] . '" />';
    $microdata .= '<meta itemprop="bestRating" content="' . $rating_form_info['max_rating'] . '" />';
    $microdata .= '<meta itemprop="ratingCount" content="' . $rating_form_info['count'] . '" />';
    $microdata .= '</div>';
	
	return $microdata;
}
add_filter( 'rating_form_microdata', 'rf_product_microdata', 10, 3 );

rating_form_site_logo

Add your site image logo in case you are missing the url attribute in rich snippet markup. Add the following code in your theme functions.php.

function rf_site_logo() {
	return 'http://website.com/wp-content/uploads/logo.jpg';
}
add_filter('rating_form_site_logo', 'rf_site_logo', 10, 3);

rating_form_itemtype

Change itemtype Article of rich snippet markup. Add the following code in your theme functions.php.

function rf_itemtype_product() {
	return 'itemscope itemtype="http://schema.org/Product"';
}
add_filter('rating_form_itemtype', 'rf_itemtype_product', 10, 3);
Vote this page:
  • 3.8/5
  • 48 ratings
48 ratingsX
Very bad! Bad Hmmm Oke Good!
14.6% 6.3% 14.6% 10.4% 54.2%