WP Recipe Maker is a popular plugin for creating recipe cards. It includes a feature to specify a Pinterest-specific image and description, just like the Shared Counts – Pinterest Image addon.
The following code will let Shared Counts use the image and description you specify in WP Recipe Maker:
/**
* Pinterest image from WPRM
*
*/
function be_shared_counts_wprm_image( $link, $id, $style ) {
if( 'pinterest' !== $link['type'] || ! class_exists( 'WPRM_Recipe_Manager' ) )
return $link;
global $post;
$recipes = WPRM_Recipe_Manager::get_recipe_ids_from_content( $post->post_content );
if( empty( $recipes[0] ) )
return $link;
$recipe = WPRM_Template_Shortcodes::get_recipe( $recipes[0] );
if ( ! $recipe || ! $recipe->pin_image_url() ) {
return $link;
}
// Build pin URL.
$url = $recipe->parent_url();
$url = $url ? $url : get_permalink();
$url = $url ? $url : get_home_url();
$pin_url = 'https://www.pinterest.com/pin/create/bookmarklet/';
$pin_url .= '?url=' . urlencode( $url );
$pin_url .= '&media=' . urlencode( $recipe->pin_image_url() );
$pin_url .= '&description=' . urlencode( $recipe->pin_image_description() );
$pin_url .= '&is_video=false';
$link['link'] = $pin_url;
return $link;
}
add_filter( 'shared_counts_link', 'be_shared_counts_wprm_image', 10, 3 );
Code language: PHP (php)