Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using filter like this to add rel attribute in wp_get_attachment_link()

add_filter( 'wp_get_attachment_link', 'sant_prettyadd'); 
function sant_prettyadd ($content) {
    $content = preg_replace("/<a/","<a rel=\"prettyPhoto[slides]\"",$content,1);
    return $content;
}

The above filter working fine except it adds the attribute even if the href points to attachment page.

I mean I want to add rel attribute only if the link points to direct image and not attachment page.

Can someone help me with this?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted
add_filter( 'wp_get_attachment_link', 'sant_prettyadd', 10, 6);

function sant_prettyadd ($content, $id, $size, $permalink, $icon, $text) {
    if ($permalink) {
    return $content;    
    }
    $content = preg_replace("/<a/","<a rel=\"prettyPhoto[slides]\"",$content,1);
    return $content;
}

Update:

function sant_prettyadd checks permalink argument.

if the permalink = true then it returns the content as it is.

if the permalink = false then it skips to the next line and replace the <a with <a rel="prettyPhoto[slides]" and then returns the content.

share|improve this answer
    
For the benefit of future generations, explain what this code does ツ ◎ܫ◎ –  brasofilo Feb 15 '13 at 8:30
    
@brasofilo Updated my answer –  Giri Feb 15 '13 at 9:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.