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.

Can't figure out why this won't work:

function my_get_attachment_link($html){
    $postid = get_the_ID();
    $html = str_replace('<a','<a rel="shadowbox['.$postid.']"',$html);
    return $html;
}
add_filter('wp_get_attachment_link','my_get_attachment_link',10,1);

Just trying to hook up all the images on a single post view to a lightbox script.

FYI, this didn't work either: http://wordpress.mfields.org/2010/thickbox-for-wordpress-gallery/#highlighter_196509

What could be jamming it up?

share|improve this question
    
In what context are you calling wp_get_attachment_link()? A copy/paste of your code works with a call to wp_get_attachment_link(36) I randomly pasted into a template. –  Milo May 14 '11 at 0:57
    
@milo: Hmmm, I thought this was getting called internally when the post page is constructed. Is that not the case? –  two7s_clash May 14 '11 at 5:35
add comment

1 Answer

up vote 0 down vote accepted

Your code only works if you are actually calling wp_get_attachment_link() somewhere in your template. If you're not calling the function, then the apply_filters() inside the function will never get called, and therefore your code will have nothing into which to hook.

share|improve this answer
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.