Set Default Image size on Attachment pages

Websites made easy

By Vincent Wondra

June 28, 2013

I was recently asked by a client to make the default image size that appears on attachment pages in WordPress to a larger images size.  To be honest, I never gave the attachment pages in WordPress a second thought.  They just showed single images or documents from the media library… big woop.  Or so I thought.  

This particular client put Adsense ads onto the attachment pages and was making a revenue stream off of those images due to traffic coming into his site via Google Image search.  By default the images in my theme (The News theme from StudioPress) were set to Medium  He wanted the images to be Large so they were more dramatic when visitors came into the pages from Google.

Thankfully it was an easy fix.

How to set the Default image size on Attachment Pages in WordPress (Genesis Framework)

Drop this code into the functions.php file

/*Set default image size on the attachment pages*/

add_filter('prepend_attachment', 'ag_prepend_attachment');
function ag_prepend_attachment($p) {
   return '<p>'.wp_get_attachment_link(0, 'large', false).'</p>';
}

To change the image size, just change ‘large’ in the above code to whatever default image size you want to show. The default media sizes in pixels are set in WordPress under Appearance–>Media

Learn more about WordPress image sizes and how they work in this must read guide.

Vincent Wondra

I'm the Founder & President of The BBS Agency & Prebuilt Sites. I have been building websites since the mid 90's. I fell in love with WordPress many years ago and today help companies leverage it's power. I'd love to help you next!