How to hide a specific image using CSS code

SHARE THIS NOW!

URL

illphated

Screenshot-2025-04-24-at-6.00.53 PM.png

hide this image

✅ Option 1: Hide by src (recommended if it’s unique)
css
Copy
Edit
img[src*=”cropped-illphated_logo-1.png”] {
display: none;
}
✅ Option 2: Hide by class
If that image is the only one with this exact combination of classes:

css
Copy
Edit
img.wp-post-image.lazy-loaded {
display: none;
}
✅ Option 3: Hide by specific size
css
Copy
Edit
img[width=”512″][height=”512″] {
display: none;
}
✅ Option 4: Hide by alt (if you set one)
css
Copy
Edit
img[alt=”Your Alt Text Here”] {
display: none;
}
Where to put this?
Inside your theme’s style.css

Or in WordPress Admin → Appearance → Customize → Additional CSS

Email

2 thoughts on “How to hide a specific image using CSS code”

  1. no by attachement ID

    ChatGPT said:
    Ahh got it — if you want to hide the image by attachment ID, you’ll need to check how it’s rendered in the HTML or how WordPress outputs it, because standard tags don’t include the attachment ID directly in the HTML.

    However, here are your best options:

    ✅ Option 1: Add a custom class using the attachment ID via WordPress PHP
    If you’re editing a theme or plugin template, you can output a custom class like this:

    php
    Copy
    Edit
    echo wp_get_attachment_image(123, ‘large’, false, array(‘class’ => ‘hide-this-image attachment-id-123’));
    Then in your CSS:

    css
    Copy
    Edit
    img.attachment-id-123 {
    display: none;
    }
    ✅ Option 2: Use CSS to target based on src if ID is not in HTML
    If the image tag looks like this and has no ID:

    html
    Copy
    Edit

    You can still hide it like before:

    css
    Copy
    Edit
    img[src*=”cropped-illphated_logo-1.png”] {
    display: none;
    }
    🛠️ Want it dynamic? Here’s how to add the ID to the class (via WordPress filter):
    Add this to your theme’s functions.php:

    php
    Copy
    Edit
    function add_attachment_id_to_image_class($attr, $attachment, $size) {
    $attr[‘class’] .= ‘ attachment-id-‘ . $attachment->ID;
    return $attr;
    }
    add_filter(‘wp_get_attachment_image_attributes’, ‘add_attachment_id_to_image_class’, 10, 3);
    Then in your CSS:

    css
    Copy
    Edit
    img.attachment-id-123 {
    display: none;
    }

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top