0

I'm trying to show a link to the full size image of an attached image. I took a code for Wordpress' Twelve Thirteen theme:

<?php 
$metadata = wp_get_attachment_metadata();
printf( '<span class="attachment-meta full-size-link"><a href="%1$s" rel="lightbox">%3$s</a></span>',
esc_url( wp_get_attachment_url() ),
esc_attr__( 'Link to full-size image'),
__( 'View Full Size' ),
$metadata['array'],
                                $metadata['array']
);
?>

It shows on the twelve thirteen theme with a magnifying class and the text 'Full Resolution (width x height). It doesn't show the theme 'terrifico' I'm using. What am I doing wrong?

2 Answers 2

1

That's not going to work, instead just use wp_get_attachment_image_src , it takes a size parameter.

// get the $attachment_id
$attach_stuff = wp_get_attachment_image_src( $attachment_id, 'full');
var_dump($attach_stuff);

You will be returned an array fo values to work with:

[0] => url
[1] => width
[2] => height
[3] => boolean: true if $url is a resized image, false if it is the original.

Also turn on debugging.

0

The below code will get you the full image url. You can use the wp_get_attachment_image to get it.

<?php 
  $metadata = wp_get_attachment_image($attachment_id, 'full');
  printf( '<span class="attachment-meta full-size-link"><a href="%1$s" rel="lightbox">%3$s</a></span>',
  esc_url( $metadata ),
  esc_attr__( 'Link to full-size image'), __( 'View Full Size' ) );
?>

if you don't have attachment's ID than use this article to get it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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