WordPress.org

Ready to get started?Download WordPress

Forums

wp_get_attachment_image custom img class (1 post)

  1. Lasha
    Member
    Posted 2 years ago #

    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!

    http://core.trac.wordpress.org/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?

Topic Closed

This topic has been closed to new replies.

About this Topic