438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
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>
334 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+4 more
cosmincotor says

Maybe this will help – link

You can set the class in the attributes array.

438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
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.

334 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+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
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
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
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
Pixelous says

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

316 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
+2 more
SyamilMJ says

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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by