Remove image style query string

Public

Snippet help you remove image style query string. This snippet using template override function theme_image_style

Get raw version
php
  1. <?php
  2.  
  3. /**
  4.  * Override theme image style to remove query string.
  5.  */
  6. function THEMENAME_image_style($variables) {
  7. // Determine the dimensions of the styled image.
  8. $dimensions = array(
  9. 'width' => $variables['width'],
  10. 'height' => $variables['height'],
  11. );
  12.  
  13. image_style_transform_dimensions($variables['style_name'], $dimensions);
  14.  
  15. $variables['width'] = $dimensions['width'];
  16. $variables['height'] = $dimensions['height'];
  17.  
  18. // Determine the URL for the styled image.
  19. $variables['path'] = image_style_url($variables['style_name'], $variables['path']);
  20. // Remove query string for image.
  21. $variables['path'] = preg_replace('/\?.*/', '', $variables['path']);
  22.  
  23. return theme('image', $variables);
  24. }

Comments

jason.enter's picture

Could you explain the context for which this would be useful?
Thanks in advance.

soumyajit's picture

hi, guys this code is not working. can you help me please.