Support » Plugins » Hacks » Single Image Display template link

  • I need to edit the link which is displayed when a single attachment is being displayed – but I don’t know where this link is put together!

    Let me explain..
    I have a Blog post which has several attachments (images):
    [URL=http://img297.imagevenue.com/img.php?image=524310877_blog_post_122_374lo.jpg][IMG]http://img297.imagevenue.com/loc374/th_524310877_blog_post_122_374lo.jpg[/IMG][/URL]

    I managed to edit the code so every image links to a page where the image itself is displayed:
    [URL=http://img253.imagevenue.com/img.php?image=524307982_blog_attach_122_459lo.jpg][IMG]http://img253.imagevenue.com/loc459/th_524307982_blog_attach_122_459lo.jpg[/IMG][/URL]

    Now the question for me is, how or where do I find the code which is used to create the last link, that is being opened when I click on this single image (and which leads to the upload folder and the image itself):
    [URL=http://img264.imagevenue.com/img.php?image=524308907_blog_attach_linksto_122_483lo.jpg][IMG]http://img264.imagevenue.com/loc483/th_524308907_blog_attach_linksto_122_483lo.jpg[/IMG][/URL]

    I need to edit this behavior, so it still displays the image from upload folder, but links to an external side.
    I can’t find where the imagelink is being created. I got as far as
    <?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>

    Which is the part that displays the image, bvut I can’t find the_content function.

    Besides, the code which is used to create the attachment links to each single image looks like this:

    <?php echo '<a class="postImg" href="' . get_permalink( $attachment->ID ) . '" title="' . esc_attr( sprintf( __( 'View' ), $att_title ) ) . '" rel="permalink">'; ?> <img width="<?php echo $image_attributes[1] ?>" height="<?php echo $image_attributes[2] ?>" src="<?php echo wp_get_attachment_url( $attachment->ID , false ); ?>" alt="<?php the_title(); ?>" width="280" border="0" /></a>

    I am new to WordPress and pretty new to PHP, too – so please forgive my stupidness!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s very challenging to find where anything happens in WP. the_content() is located in wp-includes/post-template.php. You will see there is the filter ‘the_content’ you can use. Your filter hook function is passed the entire post html. If you can figure out a way in code to search the html for that particular link and replace it, then you you have a solution. Just return the altered html from your filter hook function.

    Thread Starter Gromhelm

    (@gromhelm)

    Actually I want to have ALL imagelinks to point to a certain, external url..
    I am currently looking into post-template – I’ll let you know if I found something.
    Thanks bcworkz!

    Thread Starter Gromhelm

    (@gromhelm)

    Found it!

    function prepend_attachment($content)
    function wp_get_attachment_link($id = 0, $size = ‘thumbnail’, $permalink = false, $icon = false, $text = false )

    had to be edited. Thanks a lot bcworkz!

    Moderator bcworkz

    (@bcworkz)

    FWIW, it’s poor practice to edit core files. Both those functions have filters you can hook to alter their output, then your code will be safe from being overwritten by updates.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Single Image Display template link’ is closed to new replies.