439 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says
Hi, could somebody say how to add a class to the attachment link to an image at WordPress. For example I have such link:
<a href="http://mysite.com/wp-content/uploads/2012/05/my-image.jpg"><img title="my-image" src="http://mysite.com/wp-content/uploads/2012/05/my-image-300x256.jpg" alt="" width="300" height="256" /></a>
And need to add a class like this:
<a class="my-class" href="http://mysite.com/wp-content/uploads/2012/05/my-image.jpg">
</a>
293 posts
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
  • Europe
  • Bought between 50 and 99 items
  • Referred between 10 and 49 users
  • Envato Studio (Microlancer) Beta Tester
  • Has been a member for 3-4 years
cosmincotor says

Maybe this will help – link

You can set the class in the attributes array.

439 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says

Maybe this will help – link You can set the class in the attributes array.

But it’s for image but I need for a link.

293 posts
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
  • Europe
  • Bought between 50 and 99 items
  • Referred between 10 and 49 users
  • Envato Studio (Microlancer) Beta Tester
  • Has been a member for 3-4 years
cosmincotor says

Sorry, got them mixed up, try to get the image URL (attachment URL ), that way you can create your custom link, and place your image in it.

see wp_get_attachment_url()

or wp_get_attachment_image_src()

439 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says
Seems, I found a solution, but for some reason it isn’t work. For example, I need to add a ‘rel’ attribute to the image link. In this case I need to add a filter for default WP function ‘wp_get_attachment_link’. Look at my code please:
add_filter( 'wp_get_attachment_link', 'gallery_prettyPhoto');

function gallery_prettyPhoto ( $content ) {

    return str_replace( "a", "a rel='prettyPhoto'", $content ); 

}
Strange, but it isn’t work. :( Authors, how do you add these plugins like Pretty Photo, etc.?
439 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says

I figured out that this custom function works fine for [gallery] shortcode. Anybody here?

315 posts
  • Has been a member for 3-4 years
  • Sold between 10 000 and 50 000 dollars
  • Attended a Community Meetup
  • Exclusive Author
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
SyamilMJ says

That means you’re using the wrong hook. Try out another

by
by
by
by
by
by