Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function to add timestamp to image?
#1
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! Blush
Reply
#2
You are probably better off doing this via apache or your webserver.

The editor does not support code.

https://developers.google.com/speed/docs...es/caching
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
(2013-04-04, 23:33:37)shawn_a Wrote: You are probably better off doing this via apache or your webserver.

The editor does not support code.

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!
Reply
#4
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.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
(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)$">
Header set Expires "Thu, 15 Apr 3015 20:00:00 GMT"
</FilesMatch>

I also found:
Code:
<IfModule mod_expires.c>
# disable caching forthis directory mod_expires for this directory
ExpiresActive off
</IfModule>

Which do you think might suit better? I'm way out of my comfort level with this stuff! Wink
Reply




Users browsing this thread: 1 Guest(s)