Automatically Resize Images in WordPress?

How to automatically resize posted images

  • Open functions.php file
    function.php
  • Copy the following code into the file
function replace_image($image) {
    // if there is no large image : return
    if (!isset($image['sizes']['large'])) return $image;

    // paths to the uploaded image and the large image
    $upload_dir = wp_upload_dir();
    $uploaded_image = $upload_dir['basedir'] . '/' .$image['file'];
    $large_image = $upload_dir['path'] . '/'.$image['sizes']['large']['file'];

    // delete the image
    unlink($uploaded_image);

    // rename the large image
    rename($large_image,$uploaded_image);

    // update image metadata and return them
    $image['width'] = $image['sizes']['large']['width'];
    $image['height'] = $image['sizes']['large']['height'];
    unset($image['sizes']['large']);
    return $image;
}
add_filter('wp_generate_attachment_metadata','replace_image');

Save




For more WordPress tutorials

Follow us on Twitter
Subscribe to our Feeds
Become a Fan on Facebook
Added Sunday, March 27th, 2011. Category WordPress Keywords

One Response

Alice 03.27.2011

How big are the images when they get resize? I’m gonna try this! Thanks!


Add your comment




New Tutorials in your inbox!






Most Popular Category Today

Think Tutorial is a database of simple, easy to follow tutorials covering all aspects of popular computing. Technology is fantastic, but it can be difficult to keep up with at times. Think Tutorial's strength and success resides in its very intuitive approach and design that keeps everything simple and organized.

Statistics

TUTORIALS PUBLISHED
1,442

EQUATES TO
+3700 minutes
or
+62 hours of continuous education.

USERS ONLINE
371

AWESOME FACEBOOK FANS
5450

Why Free?

Free, easy, useful and straight-to-the-point stuff? That's what people want!

Follow Us

RSS Subscribe to Feeds
facebook Be a fan on Facebook
twitter Follow us on Twitter


© 2010-2012 Prestance, Inc. All right reserved.

All Trademarks and Brands displayed on ThinkTutorial are the sole property of their respective owners/creators and All third party trademarks are the exclusive property of the respective companies and their use does not indicate endorsement.