Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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