• The “wp_get_attachment_image” function returns an HTML img element with the ALT and TITLE attributes populated with values given from the Media Manager.

    For the CLASS attribute, however, it outputs a generic “attrachment-thumbnail-name” and there’s no way to change/customize/add to it.

    Is there some kind of a filter that can be passed to make this possible? I am no PHP expert, but I looked at the WordPress source. It looks like there’s a parameter, $attr that can be passed to the “wp_get_attachment_image” function, but the Codex doesn’t even mention this!

    https://core.trac.www.ads-software.com/browser/tags/3.2.1/wp-includes/media.php#L637

    You can see that there are a bunch of defaults defined on line 647. If I passed that last parameter of $attr with custom values, it would overwrite those defaults because “wp_parse_args” is being used on line 658.

    Can an expert confirm this?

  • The topic ‘wp_get_attachment_image custom img class’ is closed to new replies.