Need Coffee Dot Com Coffee - It's Here!
Need Coffee Dot Com!

How to Use Full Size Images in Attachment Pages

By Widge - posted 01.27.08 @ 5:38 am

Image handling in WordPress is pretty snazzy....

Uploading images in WordPress

As you can see there, I have a few options. I can show one of three things: either a thumbnail, the full image, or the title of the image. The title of the image is a mystery to me when you might use that, but here on Needcoffee we do normally the full size image. Every so often though, and that Lost in Space robot post is the most recent example, there's an image where we don't want to shrink it--we want people to be able to access it full size. So you can see the thumbnail on the post.

Once you've got the image, you've got three choices for what it does. You can either link to the file, link to a page, or no link at all. Normally we do full size and no link. But as in the Lost in Space post, we want to link out to a page that contains the full image.

Trouble is, if you do something that's too big, it will resize the image and then you have to click through the image on the page again to get to the full image. What a pain in the ass. And even worse, nobody seems to be able to say where to fix this, they just hem and haw around the question. As always.

Sokay. You can change it. Open up your *whateveryoursiteis*/wp-includes/post-template.php file.

Look for this code:

function prepend_attachment($content) {
	$p = '<p class="attachment">';
	$p .= get_the_attachment_link(false, true, array(400, 300));
	$p .= '</p>';
	$p = apply_filters('prepend_attachment', $p);

	return "$p\n$content";

That 400 and 300 are the maximum width and heighth respectively that WordPress will allow. All you have to do is change them and you should be set.

Now--the thing to bear in mind is to make sure that you don't break your theme. On Needcoffee, our content area is about 600 pixels wide, so if you see your theme suddenly get a bit bloated in the middle, you know you've put too big an image out there.

Questions? Comment away.

Read More About:

Widgett Walls is Need Coffee's Chief Cook and Bottle Washer. He is the author of the novel Mystics on the Road to Vanishing Point, and two collections of short stories, Magnificent Desolation and Something Else: The Complete First Season. He is also co-author of the children's book There's a Zombie in My Treehouse! All of those books are available in paperback or for the Kindle from Amazon. He is also the narrator and publisher of the first unabridged recording of Seneca's letters, available here. He is active on both Twitter and Facebook. (If you befriend him on Facebook, do say you came via Need Coffee.) He lives and works in Atlanta, Georgia. He hardly ever sleeps.

Keep Browsing:

« | »

A Mob Numbering 2

    I think there's a better way to do this on a theme by creating a attachment.php in your theme folder O_O

    Comment by Mummy Ninja — July 11, 2011 @ 1:36 pm


    Mummy: Well, this post was from 2008...I don't know that the attachment.php was around at that point. Or if it was, it was so poorly documented that I had to result to this. So.

    Comment by Widge — July 12, 2011 @ 1:39 am

RSS feed for comments on this post. TrackBack URI

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Google Search:
Needcoffee Web
Amazon Search:

Support Need Coffee.