janboddez / share-on-mastodon

Easily share WordPress posts on Mastodon.
https://jan.boddez.net/wordpress/share-on-mastodon
GNU General Public License v3.0
39 stars 5 forks source link

Featured image is posted twice to Mastodon #61

Closed KevinGimbel closed 1 year ago

KevinGimbel commented 1 year ago

When I set a featured image on a post it is added twice to the mastodon toot.

Post: https://nerdcultu.re/2023/02/15/alastair-reynolds-die-arche/ Toot: https://on.nerdcultu.re/@kevin/109868083982297866

In the backend I only set a featured image with no image in the post body.

Screenshot 2023-02-15 at 10 57 51

One of the images on Mastodon has a alt text, the other doesn't.

janboddez commented 1 year ago

I'm thinking you first uploaded another version of that exact same image, and then a second version with alt text. Because if they were the same file they'd both have the same alt text. Or you're running a plugin that generates a copy or something. If you check the media library, could that be the case?

The plugin by default sends both the featured image and any attachmed images (you can disable this). It's in the docs. I think disabling attached images is what you're looking for.

https://jan.boddez.net/wordpress/share-on-mastodon#share_on_mastodon_attached_images

KevinGimbel commented 1 year ago

It was actually the first one: I uploaded a different version of the image, then removed it and added another (same image, but in HEIC format). The wrong image was also still in my media library.

Still, I do not understand why the image was sent twice if I removed the "old" featured image. This feels like a bug to me.

janboddez commented 1 year ago

All attached images are included by default, not just the featured image. This allows for short (4 images max) "image galleries."

The plugin sees two different images with two different image IDs and two different alt texts and so on. So it uploads them both. It cannot know they are visually the same.

If you want to crosspost only the featured image, you should (for now) use the filter mentioned above.

The next plugin version will have a separate, "proper" setting for this too.

janboddez commented 1 year ago

I know it can be confusing, but it's how things grew "historically." From the documentation:

Share on Mastodon will also try to include attached images. (Images uploaded through the Edit Post screen. Note: These images don’t necessarily occur in the actual post in question.) This behavior, too, can be disabled, using the share_on_mastodon_attached_images filter.

KevinGimbel commented 1 year ago

I see.

As I understand this would disable adding all attached images, right? So even a featured image would not be included?

janboddez commented 1 year ago

No, a featured image (attached or not) would still be included. They're handled separately.

KevinGimbel commented 1 year ago

Nice, thank you a lot for your support again! I'll add the filter to my functions.php :)