• Resolved jonte98

    (@jonte98)


    These <img> attributes associated with the dominant color feature should be removed:

    • data-dominant-color=”63646d”
    • data-has-transparency=”false”
    • data-has-transparency=”true”

    And inline CSS can be reduced from:

    img[data-dominant-color]:not(.has-transparency) { background-color: var(--dominant-color); }

    To this:

    img:not(.has-transparency) { background-color: var(--dominant-color); }

    And it all adds up, especially when you have plenty of images. The less code, the better performance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jonte98

    (@jonte98)

    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);
    Plugin Support James Osborne

    (@jamesosborne)

    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.

    Plugin Support James Osborne

    (@jamesosborne)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Remove attributes’ is closed to new replies.