Forums

Using filter to change the image class (2 posts)

  1. timetraveller
    Member
    Posted 9 months ago #

    Hi guys,

    I am trying to get to change the image class of my child-theme. I am using Twenty-Eleven as the main theme.

    I searched around and found this:
    http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/media.php

    On line 225 is where the filter is: $class = apply_filters('get_image_tag_class', $class, $id, $align, $size);

    Beauty! So I went ahead and did this in my functions.php:

    function change_image_tag_class($class_name)
    {
    $class_name = 'colorbox';
    return $class_name;
    }

    add_filter('get_image_tag_class','change_image_tag_class');

    But when i refresh my screen, the image class hasn't changed... what am I doing wrong?

    Btw, I started using wordpress only about a week and a half ago. Maybe my understanding of filters is murky? Actions I can understand. You "do_action()" first and have it in some section of the code. Then you go ahead and create a "add_action()" so it does that action at the point where do_action() is...

    Or even that is wrong?

    Please help! It's driving me nuts! I'm trying to use colorbox and I dont wanna use plugins, I wanna do this on my own...

    Many thanks!!!

    [i apologize if this has been asked already...]

  2. timetraveller
    Member
    Posted 9 months ago #

    So i guess my add filter was correct, only that it would only apply the class to the FIRST image(s) uploaded- if you had pre-existing images, it would not work. So that definitely sucks.

    The manual way is to go ahead and add a class under the media Advanced Settings area but thats too much work. If I'm building a site for a client, they will most likely forget to do that.

    Anybody? Any solutions?

    Thanks!

Reply

You must log in to post.

About this Topic