Proof of concept – this code alters exactly as above, and it works just as before except its less code in the DOM. The inline CSS ended up optimized a bit further.
function img_attr_cleanup(){
add_filter("wp_get_attachment_image_attributes",function($attributes){
if (isset($attributes["data-dominant-color"])){
unset($attributes["data-dominant-color"]);
}
if (isset($attributes["data-has-transparency"])){
unset($attributes["data-has-transparency"]);
}
return $attributes;
});
}
add_action("template_redirect", "img_attr_cleanup");
add_action("wp_enqueue_scripts",function(){
wp_dequeue_style("dominant-color-styles");
wp_register_style('dcs',false);
wp_enqueue_style('dcs');
wp_add_inline_style('dcs','img:not(.has-transparency){background:var(--dominant-color)}');
},20);
Thanks for reaching out and sharing your suggestion @jonte98. As the plugin is open source, you’re welcome to propose any changes over the plugins GitHub repository.
If you’re not comfortable making such suggestions or if you don’t have a GitHub account I’d be happy to create a GitHub issue on your behalf, let me know and I’ll do so. I’ll also share your suggestion with the team. Many thanks.
As we didn’t receive a response I’ll mark this as resolved. Feel free to open a new support topic if you continue to encounter issues, or reopen this topic and we’d be happy to assist.