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.