• I’m looking for a way to slip an extra class into all the img tags in a post. I thought I had tracked down the function that does it in the media.php file (the get_image_tag and get_image_tag_class filters), but I can’t figure out what’s going on in there. No changes I make to it seem to have any effect and there’s nothing in the codex on how to wrangle either of those filters.

    Anybody have any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    You talk about this kind of class ? Imagine your post containers has the class called ‘entries’ :

    .entries img{
    border: 0;
    }

    In this example, it will affect all your images (only in your posts) and apply a border of 0 pixel.

    Thread Starter jjpare

    (@jjpare)

    no, not quite. what I’m looking to do is to add a whole new class to the images in the HTML, not just manipulating what already exists with CSS.

    For example, in the HTML, WordPress adds this to an image tag:
    <img class="aligncenter size-large wp-image-129"...
    What I want to do is to add another qualifier to the image class called ’tilt’.

    You see, certain elements on the site (heads and images) get rotated slightly between -2 and 2 degrees. But the rotation is controlled randomly. I add a random number generator to the functions that control those elements that creates and adds a new series of classes between ’tilt0 and ’tilt5′.

    I’ve managed to do this for all the other elements I need to, but I can’t figure out the function that adds those classes (‘aligncenter’, ‘size-large’, etc.) to the images. It does appear that the get_image_tag function in the media.php file is the one that does it, but I can’t quite figure out how to take control of it. And it doesn’t help that there is absolutely no mention of the get_image_tag filter anywhere in the codex, and that other forum queries on the subject have received almost no response whatsoever.

    If it makes any difference in the answer, what I’m working on is a child theme of Thematic.

    i played around a bit, and it seems, that the ‘get_image_tag()’ function (and the filter ‘get_image_tag_class’) in media.php only gets applied when an image is inserted into a post for the first time (not even if the image is updated)

    also:
    https://www.webtechwise.com/wordpress-filter-examples-changing-attributes-when-adding-images-to-posts/

    Thread Starter jjpare

    (@jjpare)

    Alchymyth: Thank you!
    That was totally what I was looking for.

    I’m still at that stage where I can read and repurpose existing PHP and Java script, but not so much writing it from scratch. So this was a huge help. ??

    “it seems, that the ‘get_image_tag()’ function (and the filter ‘get_image_tag_class’) in media.php only gets applied when an image is inserted into a post for the first time (not even if the image is updated)”

    Wow, thank you so much for mentioning that, I’ve been banging my head against this for a while and I don’t know how much longer it would have taken me to figure that out myself. I haven’t seen anything that talks about it mention that, so I’d assumed, since it’s part of my theme, that it would apply when it displays.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding an extra class to post images’ is closed to new replies.