• Resolved pnaw10

    (@pnaw10)


    Here’s the problem I am having: I published a post and it was instantly shared to Facebook. For some reason, WordPress flaked out and while the content of my post was fine, the Featured Image (and a few SEO things) I specified did NOT save to the post when I published it. As a result, the “default / fallback” image I’ve specified in RankMath was used by BSI.

    I quickly re-added the specific Featured Image I wanted for this post and updated the post, but Facebook already cached the original og:image URL, so even if I rescrape the post’s URL, Facebook refuses to recognize the new image.

    According to Facebook’s support pages, this is intentional — the only way to force FB to recognize image changes is to “Use a new URL for the new image or the image won’t be updated.”

    The problem is, I can’t change the URL of the image BSI outputs. But rather than asking for an option to change image filenames, I think there may be a better option:

    People with similar issues on StackOverflow got some responses suggesting that a random string be added at the end of the URL. So instead of the default BSI image URL ending in social-image.jpg/ could the plugin be changed to something like social-image.jpg/<strong>?v=<?php echo rand() ?></strong> or maybe instead of a random number, it could just be a timestamp or even some kind of number that would just increment every time the post is saved?

    The suggestion was that adding a random number after the URL (a number that would be updated each time the post is re-published) would “trick” Facebook into thinking there’s a different image URL, so rescraping would result in the correct image being displayed, rather than the original one. And since it’s just a random string that doesn’t affect the URL itself, it wouldn’t have any harmful impact on previously-shared links.

    This would be helpful for two reasons:

    • If someone has a problem like mine, where the intended featured image didn’t get saved properly, or if they forget to add one or they initially choose the wrong image, and then need to make a correction.
    • If a website rebrands and wants to refresh its og:image content so that they show their new design/logo/etc. rather than the old one.

    Another person on StackOverflow suggested that the og”updated_time tag would force Facebook to also update the image, but my posts already have this OG tag included and Facebook is not seeing any changes — because the og:image URL never changed, only the image itself changed. In order for Facebook to “see” the new image, it needs to be fed a different URL for the og:image.

    I wanted to edit the plugin to try this for myself before filing a request, but my coding skills are fairly limited. I tried to find the appropriate code that would need to be adjusted to test this theory out, but I was having doubts. Hopefully someone else — whether it be the developers or fellow users — might have a better idea of which line(s) of code could be adjusted to see if this would work. If I know what to adjust, I’d be happy to try it myself and report back on the results.

Viewing 1 replies (of 1 total)
  • We will plan a permanent solution for this in version 1.1.0, and I will create a bugfix release 1.0.20 for this soon.

    Edit: 1.0.20 should be available soon

    Implement a filter like this:

    add_filter('bsi_image_url', function($url) { return add_query_arg('_', time(), $url); });

    to add a timestamp to the url.

    This will change the OG:Image URL every second. For version 1.1.0 we’re planning the option to add the actual timestamp of last change.

Viewing 1 replies (of 1 total)
  • The topic ‘Request: Add Timestamps or Random String to image URLs’ is closed to new replies.