And,,, it’s done. It wasn’t too bad, though maybe a little hacky/only for me.
What my version does:
1. Adds the option for pinterest to be selected on the various menus on the admin side:
allsites.php:
'service' => 'share,follow',
'share_url' => "https://pinterest.com/pin/create/button/?url=URI&media=MEDIA&description=TITLE",
2. Replaces MEDIA with the url of an appropriate picture:
share-and-follow.php
https://jon.limedaley.com/share-and-follow.phps
(Unfortunately, the share-and-follow plugin seems to be no longer in the wordpress repository? and I didn’t think to keep an original copy before I edited it. If someone has an original, I can do a proper diff on the file.
Basically, all I did was to add a new parameter to the replaceKeywordsInURL function that looks for MEDIA and replaces it with the image URL.
The image URL is calculated in social links:
$image = '';
if($page_id){
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches);
$image = $matches[1][0];
if(!$image){
// you might like this function instead: get_post_meta($page_id, 'image', true);
$image = recipress_recipe(get_post($page_id), 'photoraw', array('max' => 1, 'size'=>'medium'));
if(count($image))
$image = $image[0];
else
$image = '';
}
}
I’m using the “recipress” plugin, though the author was apparently not interested in my modifications and so never responded to my emails about how to send her my code, so I have a heavily customized version (and the above call won’t work for you), so you might just like this version instead, which doesn’t look for custom fields:
$image = ”;
if($page_id){
$output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, get_the_content(), $matches);
$image = $matches[1][0];
}`
This will look for the first image in a blog post and use that image to share on pinterest.