So rather than going down that road, let’s instead explore the ways you can leverage WordPress to get the most out of your images. Below you will find 10 code snippets that will enable you to use images more effectively in WordPress. And I don’t need to tell you that’s a good thing, right?

1. Remove Automatic JPEG Compression

Ensuring that your images are as small (and therefore quick to load) as practically possible is vital, which is why I so heartily recommend the WP Smush.it and TinyPNG for WordPress plugins, which compress JPEGs and PNGs so effectively that you are highly unlikely to notice the difference.

If you have those plugins installed and you’re compressing your images as you see fit yourself, you almost certainly don’t need WordPress’ built-in JPEG compression capabilities, which by default compress the web’s favorite image file type to 90% of its original quality. You can effectively turn off this function by using the following code:

2. Add a Favicon

I never cease to be amazed at how many websites don’t have a custom favicon. It’s not the biggest deal in the world, but at the same time it’s a task so easily completed that every website worth its salt should have one.

You can create a favicon from scratch or create from your logo using a web app such as favicon.cc. Once you’ve done that, upload your shiny new favicon to your theme’s root folder (i.e. /wp-content/your-theme-name/) and enable its display using the following code:

3. Display Your Favicon as the Gravatar

If you don’t have the time or the inclination to create a custom favicon, a quick and easy alternative is to use your pre-existing Gravatar (hint: you’ll want to get yourself one of these if you don’t already).

The Gravatar attached to the email address listed in your WordPress profile will be used as your favicon; just enter the following code into functions.php and WordPress will do the rest!

4. Add Theme Support for Featured Images

Before you do anything else, you’ll want to make sure that your theme supports featured images (previously known as post thumbnails). This is a really important step for image optimization in WordPress.

It almost certainly will, but if it doesn’t, just add the following code to functions.php:

5. Require a Featured Image Before You Can Publish a Post

As a rule of thumb, every one of your blog posts should have a featured image.

With that in mind, it can be especially useful to enforce the inclusion of a featured image; either if you run a multi-author blog and you want to make sure that your writers are adhering to your requirements, or if you run your own blog and tend to get a bit forgetful at times.

If you add the following code to your functions.php and try to publish a post that doesn’t have a featured image, you will receive the following message: “You must select a Featured Image before your Post can be published.”

6. Show Featured Images in Your WordPress Blog’s RSS Feed

By default, featured images are not shown in your blog’s RSS feed. This is no good at all, and is high on my list of must-change tasks when designing a new site and making WordPress work better with images.

Fortunately, the solution is simple enough. Just use the following code snippet:

8. Remove Width and Height from Inserted Images

By default, WordPress adds width and height attributes (in HTML) to each image that you insert into a blog post or page.

Under most circumstances this is desirable, as it ensures that the appropriate room is made for the image within your design, even if the image itself is still loading. However, there are times when these ‘hardcoded’ dimensions will directly contradict something you are trying to achieve with CSS.

If you ever find yourself in that quandary, just use the following code to remove the width and height attributes from your images in WordPress:

9. Add Your Logo to the Login Page

Let’s finish off this roundup with a couple of backend branding snippets.

First we’ll add your logo to the WordPress login page (http://yoursite.com/wp-login.php). If you’re running a multi author blog or creating a website for a client, this will add a little extra sheen to the backend.

Just add the following code and upload your logo (feel free to change the file location to suit):

What Next?

Above are the best image-related WordPress code snippets I could find, but they’re certainly not alone. Customization in WordPress is practically limitless, and there is a lot more that you can do than I’ve listed above.

With that in mind, do you have any favorite code snippets that you like to use? Or is there a specific function that we haven’t listed above that you would like to be able to use? Let us know in the comments section below!