• Resolved kbkisan

    (@kbkisan)


    Hi there, I was wondering if anyone could help me out with a problem. I have been browsing the internet to try to figure out how to create a filter for the wp_get_attachment_link in wordpress to add custom rel and href values. What I found out so far is this filter

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

    Basically what this does is change the rel and output the normal href to the image but I would like to substitute it somehow with this:

    href='javascript:void(0);' rel="{gallery: 'gal1', smallimage: '<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'preview-main', false, '' ); echo $src[0]; ?>',largeimage: '<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large', false, '' ); echo $src[0]; ?>'}"

    But I can’t figure out how to include something like this in the filter

    Thanks in advance

  • The topic ‘Create filter for wp_get_attachment_link’ is closed to new replies.