Function to add timestamp to image? - Printable Version +- GetSimple Support Forum (http://get-simple.info/forums) +-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3) +--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16) +--- Thread: Function to add timestamp to image? (/showthread.php?tid=4589) |
Function to add timestamp to image? - trmash - 2013-04-04 Hi all, I'm hoping there is some way I can add a timestamp to images within the content in order to prevent caching, but I'm not really keen to alter the core code. Can this be done with a function? For example, within my client's template is <img src="<?php get_site_url(); ?>/data/uploads/image.jpg?<?php echo date("W");?>" /> which simply adds the week number to the end of the image, and means the image will not be cached forever until the user clears it. How can I add the same timestamp to certain images which are called from within the content editor to prevent them being cached too? The images will be updated once every week or two, but the page content does not necessarily change. If I HAVE to edit the core code, so be it (though I have no idea where) - but surely someone smarter than me can advise how I could create a function to achieve this. Much appreciated! RE: Function to add timestamp to image? - shawn_a - 2013-04-04 You are probably better off doing this via apache or your webserver. The editor does not support code. https://developers.google.com/speed/docs/best-practices/caching RE: Function to add timestamp to image? - trmash - 2013-04-05 (2013-04-04, 23:33:37)shawn_a Wrote: You are probably better off doing this via apache or your webserver. Thanks for the reply. Just to clarify, I didn't mean that I need it to be done within the editor itself. I know mvlcek wrote a very handy plugin to remove the paragraph tags from images (that have been inserted via the editor) when the page loads, I was just wondering whether a similar plugin could be fashioned to add a timestamp after the image's file extension. The reason I asked is that I am not overly familiar with preg_replace and the like. I don't want to prevent all images used in the theme from caching (which is what I suspect would happen using Apache or similar), just these ones being inserted by the user via the editor. Cheers! RE: Function to add timestamp to image? - shawn_a - 2013-04-05 Well typically you use expire or other headers depending on the files you could control it via upload sub folders or wild card file names. RE: Function to add timestamp to image? - trmash - 2013-04-05 (2013-04-05, 09:16:24)shawn_a Wrote: Well typically you use expire or other headers depending on the files you could control it via upload sub folders or wild card file names. Could it work with a .htaccess file in the directory where these particular images are uploaded? Because they'll always be in the same place. I found this example: Code: <FilesMatch "\.(jpg|jpeg|png|gif)$"> I also found: Code: <IfModule mod_expires.c> Which do you think might suit better? I'm way out of my comfort level with this stuff! |