Maximum Image Size On Front Page

Posted on 2010-11-10
Last Modified: 2012-05-10

I am wondering if a code exists to resize images on the front page so that they fit within the column widths. I do not use the media uploader in WP. Instead, I upload my images to image folders within my site and link using the standard IMG command.

The front page displays the entry in a two column layout that is smaller than my standard image size (700px). However, single article pages do not have the sidebar and thus expand the content area to accommodate the images.

Is there a code I can add to the front page file that will resize any images bigger than 500px to a set size (i.e. 500px)?

Thanks all!
Question by:laubacht
  • 2
  • 2
  • 2
  • +1
LVL 23

Expert Comment

ID: 34107974
I am not positive I completely understand all of your requirements. I will start off by providing a link to an article which I believe addresses what you are asking for. Let me know if I am wrong, and I will look again.

LVL 15

Accepted Solution

AndyBeard earned 334 total points
ID: 34108903
The easy way is to just use CSS and rely on a browser to do a sufficient job of rendering the image.

The programming solution would be to use something like

You could then write some javascript/jquery that would modify each image URL and pass it to timthumb

Alternatively if you uploaded smaller versions each time, you could just use some javascript to modify image src.

Author Comment

ID: 34109376
Thanks guys, I am going to give both options a look and test them out..

Jeremy, basically what I am going for is a resize on the front page to fit the column width.  Since I run my images through a program that resizes, renames, and watermarks all my images, I upload them via standard FTP to a directory in my site to which I store them and call them via IMG SRC commands to post into pages.  With that said, I do not use the media tools supplied by Wordpress.  The issue is my standard resize is 700px wide; my front page column for an article is only 500 pixels wide.

If you go to my website (, you'll notice that the images in the first entry spill out on the right cause they are too big.  However, if you open up the single article page which has no sidebar (and thus is only one column), it'll fit fine.

What I want to do is make it so any articles displayed on the front page automatically resize my image to a specified size (or percentage) so it'll fit on the front page.  But if a user opens the single article, it will display as normal.

Its hard to make sense of this, but that's something I hope makes sense.

Below is a code sample I found today...

So something like that perhaps?

To better give a visual, go to my front page at and scroll down to the first article titled "First Snow Of 10/11 Season".  Notice how the image of the three cars with the snow falling is too big for the column (its 700px by default) and thus spills out on the right side.  If you display the article on its own (via, it fits fine given the lack of the sidebar.

What I want to do is make it so images being displayed on the front page automatically get displayed with a smaller width so they fit, but then display like normal when on its own.

Does that help a bit?

Thanks again guys!
.rt-article-content img {

Open in new window

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


Assisted Solution

by:Sam Cohen
Sam Cohen earned 166 total points
ID: 34109501
If the wordpress theme is already coded to show the image..look for that code and just add width="500" or style="width:500px;" to the image tag of the not add a height attribute

Expert Comment

by:Sam Cohen
ID: 34109507
or if you want to use instead ...
just add height="500" or style="height:500px;" to the image tag of the loop...but DO NOT add a width attribute
LVL 15

Assisted Solution

AndyBeard earned 334 total points
ID: 34109627
The css route is really easy... though much easier if just one of those nested DIVs, or just a unique class was applied to all your historical photos.

then you could just add this to your CSS

.home .imghome {max-width:500px;}

You could use that aligncenter if it isn't used for anything else anywhere.

That being said it will squish things.

Probably the best solution possible is to create a shortcode

We can grab a shortcode from this post

// Image resize in content
function timmyimg($atts, $content = null) {
            'w' => '540',
            'h' => '250',
            'class' => 'alignnone',
            'alt' => ''
      ), $atts));
      return "<img src='". get_bloginfo('template_directory') . "/timthumb.php?src=".$content."&w=".$w."&h=".$h."' alt=".$alt." class='wp-post-img ".$class."' />";
add_shortcode('img', 'timmyimg');

Then modify it with a is_singular conditional to return an unmodified width.

thus something like

if is_singular {

return "<img src='" . $content . "' alt=".$alt." class='wp-post-img ".$class."' />";

} else

return "<img src='". get_bloginfo('template_directory') . "/timthumb.php?src=".$content."&w=".$w."&h=".$h."' alt=".$alt." class='wp-post-img ".$class."' />";

I am sure there are some bugs in that but you will get the idea. (I just tinker with code)

Author Comment

ID: 34199659
So the trick was to modify my template.css file to include the lines of code below.. this adjusted the images displayed onthe front to a max size of 600px, maintain the aspect ratio of the original image, but display the image normally on the single post pages.
.rt-article-content img {

Open in new window


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is the WordPress Exit hook? 1 29
Wordpress French and English Site 6 76
tiny glitch in my main slider 3 38
What's this? As a volunteer Page Editor for, I have noticed that many authors also have blogs, and pull articles from their blogs to post at Experts-Exchange. I appreciate each author sharing their blog content with our site …
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Open Page or Post…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question