I have custom attachment.php, I want to give link for images in single.php so if user click that images, will redirect to attachment.php is that possible?

Here is the example of code.

<a href="link for redirect to attachment.php"><img src="folder/logo.png"></a>

Thank you before


1 Answer 1


I am not sure what you mean by "redirect" there. attachment.php is meant to be used as theme template file. Loading it directly it won't be able to access WordPress core properly.

In usual WordPress mechanics you can use get_attachment_link() to form URL itself or wp_get_attachment_link() for whole link HTML.

  • So like this if I am use your code? <a href="<?php wp_get_attachment_link();?>"><img src="folder/logo.png"></a> . But the link of images still like the_permalink .
    – Kholis.net
    Dec 21, 2014 at 12:58

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