Note that there are some explanatory texts on larger screens.

plurals
  1. POWordPress add filter to wp_get_attachment_link
    text
    copied!<p>I need custom class for filter to wp_get_attachment_link. So what I so:</p> <pre><code>function modify_attachment_link( $markup ) { global $post; return str_replace( '&lt;a href', '&lt;a class="view" rel="galleryid-'. $post-&gt;ID .'" href', $markup ); } add_filter( 'wp_get_attachment_link', 'modify_attachment_link' ); </code></pre> <p>It's work fine. But what I need to do in case if Link thumbnails to: Attachment Page I mean I don't need a custom class at this case. Any help please?</p> <p>And core function for wp_get_attachment_link is:</p> <pre><code>function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) { $id = intval( $id ); $_post = &amp; get_post( $id ); if ( empty( $_post ) || ( 'attachment' != $_post-&gt;post_type ) || ! $url = wp_get_attachment_url( $_post-&gt;ID ) ) return __( 'Missing Attachment' ); if ( $permalink ) $url = get_attachment_link( $_post-&gt;ID ); $post_title = esc_attr( $_post-&gt;post_title ); if ( $text ) $link_text = esc_attr( $text ); elseif ( $size &amp;&amp; 'none' != $size ) $link_text = wp_get_attachment_image( $id, $size, $icon ); else $link_text = ''; if ( trim( $link_text ) == '' ) $link_text = $_post-&gt;post_title; return apply_filters( 'wp_get_attachment_link', "&lt;a href='$url' title='$post_title'&gt;$link_text&lt;/a&gt;", $id, $size, $permalink, $icon, $text ); } </code></pre> <p>So I mean if ( $permalink ) I don't need to add custom class for this function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload