WordPress.org

Ready to get started?Download WordPress

Forums

?ver on image url (4 posts)

  1. stev_mcguire
    Member
    Posted 1 year ago #

    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.

  2. bcworkz
    Member
    Posted 1 year ago #

    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.

  3. stev_mcguire
    Member
    Posted 1 year ago #

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

  4. bcworkz
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.