438 posts
  • 3 Years of Membership
  • Author Level 4
  • Collector Level 3
  • Exclusive Author
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>
356 posts
  • Affiliate Level 2
  • Author Level 5
  • Beta Tester
  • Collector Level 3
+4 more
cosmincotor
says

Maybe this will help – link

You can set the class in the attributes array.

438 posts
  • 3 Years of Membership
  • Author Level 4
  • Collector Level 3
  • Exclusive Author
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.

356 posts
  • Affiliate Level 2
  • Author Level 5
  • Beta Tester
  • Collector Level 3
+4 more
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()

438 posts
  • 3 Years of Membership
  • Author Level 4
  • Collector Level 3
  • Exclusive Author
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.?
438 posts
  • 3 Years of Membership
  • Author Level 4
  • Collector Level 3
  • Exclusive Author
Pixelous
says

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

316 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • 4 Years of Membership
+2 more
SyamilMJ
says

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

by
by
by
by
by
by