Pinterest Pin ID
-
Hi, Robin. Great plugin. Thanks for adding Pinterest support. I’m not sure we know yet how much difference adding a Pin ID provides, but I was wondering if there’s a way to add that as well to the Pinterest image and description. Pinterest says that when it pins an item with a Pin ID, it tags it as a repin which apparently provides some added value.
-
Looking at the Pinterest developer documentation on this, it looks like accessing a pin’s ID requires setting up an API app, as the ID has to be retrieved dynamically from Pinterest. This plugin is intended to be very minimal–it doesn’t query Pinterest at all, just builds the button URL–so adding in the Pin ID appears to be outside the scope of what this plugin could do.
I could be wrong, but I think – based on this article by Pinterest – it is something that you can just retrieve yourself and add to the image src property. So maybe it could be a field, much like the custom image field, where you can drop in the pin ID?
More details here:https://business.pinterest.com/en/blog/pin-it-button-technical-tune-up-5-tips-to-make-sharing-from-your-site-better
Thanks for sharing that link, I appreciate it. It looks like if you have the pinit.js on your site, it will automatically add the pin ID if your image includes a data-pin-id attribute, but that’s tied to the specific image, and the script, not the sharing button itself. Hypothetically, I suppose it would be possible to add the pin ID to the optional hidden image output, but I suspect that without the script, it wouldn’t do anything, since the sharing button link contains all of the data for the Pinterest pin. I’m willing to consider it, but I don’t know enough about it to know if it would do any good. (Also, how many bloggers would be interested enough to manually add the pin ID to their post? Honest question)
Ah, I see – that makes sense!
I can’t speak for other bloggers, but I know I’d definitely be interested enough to manually add the pin ID. Having it count as a repin, rather than a new pin, makes it a lot easier to track on the analytics-side to see how much exposure your content is getting on Pinterest (if you have a business Pinterest account).
I don’t know enough about the pin ID set up to feel comfortable committing to this at this time, but I’ve just updated the plugin to make it fairly straightforward to modify the hidden Pinterest image attributes to include the data-pin-id attribute.
Review this commit and the example code below it. If you have a test/staging site, you could try it by replacing the pinterest output file and adding this filter, and manually setting custom fields.
This is added to the hidden Pinterest image, not to the sharing button URL, which doesn’t currently accept a pin ID as a parameter.
I too would be interested enough to manually add the pin ID to a custom field. I’ll review your Github commit. My development skills are currently minimal, but I may be able to create my own staging area with your code snippets. Thank you. You’ve already done a great job with this plugin. I’d like to understand PHP as well as you apparently do.
Thank you both for your comments and interest. I’ve just updated the plugin to version 3.1.0, so you can use that for testing the filter. I would appreciate hearing back once you’ve had a chance to test and see if this does correctly get the pin ID information where it needs to be.
Thank you Robin! I’ll do this today and report back!
Sorry, just to make sure I’m doing this right: I’ve installed the version 3.1.0. So all I need to do (apart from adding the custom field within the post itself) is add the add_filter code you provided to my theme’s child functions.php file? Or is there somewhere else that code should go?
Thanks!
MeganYes, you can add it to your theme’s functions.php file, although if you change themes and want to keep it, you’ll need to copy it to your new theme. Just make sure your files are backed up before you edit, and practice safe coding. I tested it locally, and it worked for me, but you’ll want to verify for yourself.
If the custom field is not present, the pin ID will not be added to the hidden image.
You are the bomb! I added the filter to my child’s function.php and the custom field “scriptless_pinterest_pinid” to the post as you directed in GitHub. I checked the source code for the post and, sure enough, the image attributes outputted the test pin ID number I added to the custom field value.
I’m still developing the primary website that will use your plugin and the great integrated Pinterest support. So right now, it’s working off my Synology web station. I’m going to see if I can implement it sooner on a live website.
Thanks again.
I don’t know why it doesn’t work for me. I used generatepress theme. I add the following code on my theme function.php file
add_filter( ‘scriptlesssocialsharing_pinterest_image_attributes’, ‘rgc_sample_pin_id’ );
/**
* Add data-pin-id to the hidden Pinterest image attributes, if the
* custom field has been manually added.
*
* @param array $attributes
* @return array
*/
function rgc_sample_pin_id( $attributes ) {
$pin_id = get_post_meta( get_the_ID(), ‘scriptless_pinterest_pinid’, true );
if ( $pin_id ) {
$attributes[‘data-pin-id’] = $pin_id;
}return $attributes;
}is there anything else I have to do?
Thanks for your time.Have you added the pin ID to the post with the correct name and value? See the note below the example code on Github:
Just add the Pinterest pin ID manually as a custom field with the name as
scriptless_pinterest_pinid
and value as the pin ID, which would have to be looked up on Pinterest.I have 15 images in a post, how can I add the custom field for all images?
The custom field only applies to the hidden Pinterest image. To add anything to other images in your post content, you would have to edit them manually. (Note: from what I can tell, I think the pin ID requires the Pinterest JavaScript to work, so adding it to this plugin’s output is completely theoretical.)
- The topic ‘Pinterest Pin ID’ is closed to new replies.