WordPress.org

Support

Support » Plugins and Hacks » Hacks » ?ver on image url

?ver on image url

  • Hello, i am looking into adding a variable on to end of an image url, e.g.

    http://www.mydomain/wp-content/uploads/2012/10/image.png?ver=20120910

    I wish to use this so I can ensure updated images are shown correctly in the visitors browser.

    I notice this convention is used on the word press logo on the wp-admin page.

    The variable I wish to add to the image is the last modified date.

    I have tried a number of methods, php with filemtime () an curl() to get the images headers, i have managed to retrieve the information using curl but am now at a loss as to append the data to the image url.

    I have also look into using jquery to get all images on the page then get the last modified date, this has been unsuccessful too.

    Any help would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could hook the filter ‘wp_insert_post_data’ or similar, and search the passed post content for embedded image source urls. This filter might fire on updates, so you may need to check for existing variables, you’ll need to verify this to be sure.

    Then it’s just a matter of getting the image header info, then inserting you variables into the post content at the right places before returning the whole thing.

    Cheers, i will look into this, I assume the hook mentioned will only allow add the ver on new posts / pages?

    Don’t assume. Investigate 🙂 I’m not sure myself.

    Just write a quick temporary hook function for that filter that just dies with “I was called” or something. Then update an existing post and see what happens.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘?ver on image url’ is closed to new replies.