wp_get_attachment_link
-
I’m using wp_get_attachment_link to link an image on my front page to the post. But it sends me to a post with the name of the attachment as the name of the post. So, the url ends up something like:
‘https://mysite.com/category/title/attachment/image-name’
Is there a way to do this so that it goes to the post instead of to the attachment?
Here’s the code I’m using on my home page:
‘$args = array(
‘post_type’ => ‘attachment’,
‘numberposts’ => 5,
‘post_status’ => null,
‘post_parent’ => null, // any parent
‘order’ => ‘DESC’,
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
setup_postdata($post);
echo wp_get_attachment_link($post->ID, ‘medium’, true);’
- The topic ‘wp_get_attachment_link’ is closed to new replies.