Skip to content

Instantly share code, notes, and snippets.

@Christian-Roth
Last active February 18, 2017 10:13
Show Gist options
  • Save Christian-Roth/fdc34dc88935087aa494 to your computer and use it in GitHub Desktop.
Save Christian-Roth/fdc34dc88935087aa494 to your computer and use it in GitHub Desktop.
Function to reverse the order in the WP srcset array
function reverse_srcset_order($atts) {
if (isset($atts['srcset'])) {
$srcset = explode(', ', $atts['srcset']);
$srcset_reversed = array_reverse($srcset);
$atts['srcset'] = join(', ', $srcset_reversed);
}
return $atts;
}
add_filter('wp_get_attachment_image_attributes','reverse_srcset_order',1,1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment