I have archive-page.php
, where my custom posts are displayed. I want to put a link on my image, <a href="" alt=""><img src="" alt=""></a>
, which leads to single-page.php
for that particular post or product. How can I do that?
I have tried this:
<a href= "<?php get_the_permalink ();?>" alt=""><img src="" alt=""></a>
but it does not work. I don't know what to put in functions.php
and in those pages: archive-page.php
and single-page.php
I have archive-page.php
, where my custom posts are displayed. I want to put a link on my image, <a href="" alt=""><img src="" alt=""></a>
, which leads to single-page.php
for that particular post or product. How can I do that?
I have tried this:
<a href= "<?php get_the_permalink ();?>" alt=""><img src="" alt=""></a>
but it does not work. I don't know what to put in functions.php
and in those pages: archive-page.php
and single-page.php
get_the_permalink()
doesn't echo
anything. It just returns a string so that you can further manipulate it.
You need the_permalink()
instead, which will echo
the link.
The difference used to be clear in the Codex but now, in the much inferior, "developer" code reference toward which WordPress is migrating it is not so clear.
As explained by this answer,
<a href= "<?php get_the_permalink ();?>" alt=""><img src="" alt=""></a>
should be
<a href= "<?php echo get_the_permalink ();?>" alt=""><img src="" alt=""></a>
OR
<a href= "<?php the_permalink ();?>" alt=""><img src="" alt=""></a>