Primary Menu

Some themes like to use the admin account’s avatar, if available, in the header of the theme to highlight the author. However, it’s nice to be able to change that image if the admin email’s avatar is not appropriate nor changeable.

The free Automattic theme Writr, by our very own Thomas Guillot, takes the approach of using Custom Headers for customizing the avatar image. In short, we’ll be using Custom Headers to output our image, and its default image argument will allow us to insert the avatar when no custom header image has been uploaded. Let’s get started!

Finally, our writr_get_default_header_image function fetches an image from the Gravatar service. If there’s no account matching the admin email sent, we can request another image to be returned from Gravatar; we’ll try to match it to the “Default Avatar” value in Settings → Discussion (that’s all that $default business). More detail on the arguments being sent can be found in the Gravatar Image Requests documentation.

Did you know that there’s a WordPress.com-specific version of Underscores?

By adding a special parameter, your download will include special code used only in themes on WordPress.com. Use it to make the greatest theme ever, and send it in to themes [at] automattic.com for consideration!

Website performance is a daunting, complicated subject; everything from servers, networks and the code itself affects the length of time it takes for our carefully-crafted pixels to arrive on the screen of our viewer. However, when it comes to WordPress themes, there are a few simple guidelines we can follow to make sure our themes help, rather than hinder, that process.

There is a single, unifying concept behind all of the following practices: less is more. Performance can be improved every time we:

reduce the amount of data we fetch,

reduce the time required to fetch that data, and

reduce the number of times we have to fetch data at all.

Image Handling

Images require special treatment to not get in the way of performance. These tips will make sure any images you require are as lean as possible.

Many images can be further compressed before suffering any visible loss in quality. Make sure any included images in your theme are compressed, either with your favourite image editor, or a tool like PNGCRUSH. Use the image format (JPG, PNG, or GIF) that best suits your situation and results in the smallest file size.

The best way to reduce image size? Don’t use them at all. If all you need are icons, use an icon font (like Genericons) instead, or the vector format SVG. Use CSS whenever possible for graphic elements, such as spinners or loaders.

If you must use multiple small images, combine them into a single file as CSS sprites, to reduce their download to just one HTTP request.

Scripts and Stylesheets

Scripts and stylesheets add up quickly. Simply adding third-party scripts and libraries that cover all edge cases can result in a lot of un-necessary code, while comprehensive CSS frameworks can also amount to needless data. Keeping in mind our mantra of less is more, two further action points can bring significant improvements to our page loads.

Enqueue scripts and stylesheets only on the pages that require them. See the Twenty Fourteen default theme for an example of how CSS and JS for the slider are conditionally loaded for just the home page.

Transients

Web servers have a very repetitive job. If ten users request our website in one minute, and nothing has changed on that page in that minute (a new post, categories removed, menus changed), it’s a bit of a waste for the web server to keep querying the database for the same information every time. This is where caching comes in. Caching is the general idea of doing the time-consuming data fetching one time, storing the results, and then delivering those stored results the next time someone asks for that same page. While the details of caching are far beyond this article, suffice it to say that the more our theme code can take advantage of caching, the speedier our sites will be – and the Transients API is a simple tool for theme developers to do just that.

Testing

Google’s PageSpeed Insights tool is extremely helpful when measuring performance of your sites in general. While some of it will not apply directly to theme code, it can point out issues with large images, unminified assets and more. There are two versions: a web version and a Chrome extension. The web version is usually more up-to-date (and now includes mobile-specific tests), while the extension can be used for offline, local testing.

Pingdom offers a suite of tools for web developers, one of which is the Website Speed Test. While PageSpeed is an overall review of best practices, Pingdom’s page test is focussed on load time, with the number of requests and load size for context.

Wrap-up

Getting content in front of our users as fast as possible is more important than ever these days, particularly considering the growing use of mobile phones and tablets. If we want content in front of our user within one second, we need to squeeze every millisecond we can get out of our themes and WordPress installs. Performance is an ongoing, incremental process which, with these guidelines and regular education, will keep your themes in top shape for all of your visitors, mobile and up. Remember: less is more!

Default theme developer, Konstantin Obenland (who helped build the last three themes that shipped with WordPress!), shares some insight into the design and development of previous default themes, and proposes an interesting approach to the development of Twenty Fifteen. Twenty Fifteen →

Some news on recent changes for WordPress 3.8 that make theme development even easier:

Post Formats

From 3.8 onwards, theme developers will be able to check if a post has any post format associated by checking has_post_format() without passing an argument:

// Does the post have any format assigned to it?
has_post_format();
// Does the post have this specific format assigned to it?
has_post_format( 'aside' );
// Does the post have any of these formats assigned to it?
has_post_format( array( 'aside', 'image', ) );

Background Images

Additionally, it is now possible to be more specific about a theme’s custom background support. You can now specify default-repeat, default-position-x, and default-attachment arguments for background images. This is the full array of defaults when registering theme support now:

Miscellaneous

With the improved theme experience in the Appearance menu, WordPress can accommodate for even bigger screenshot sizes of your theme, the new standard size is now 880x660px!

If you have themes in the WordPress.org repository or plan to release a theme there (you should!), these three tags will be available to classify your theme appropriately: responsive-layout, fluid-layout, fixed-layout.
They replace fluid-width and fixed-width, to make the terms broader and match web design terminology better. You can also classify your theme as accessibility-ready – if it is.

0.0000000.000000

Post navigation

A recent creation from Automattic’s Takashi Irie,Resonar is an elegant theme perfect for fashion, food, or design blogs. Its layout showcasing full-screen featured images works especially well for longform posts with large images. Combine strong images with Resonar’s beautiful typography to craft posts that make an immediate visual impact.

A new theme designed by Automattic’s Tammie Lister is now available in the WordPress.org directory. Coherent‘s elegant slide-out panel tucks away navigation, a social menu, and widgets, keeping visitors’ focus on your posts. Optional full-screen featured images let you showcase strong photos or other graphics.

Delve into the Underscores starter theme in Jeff Chandler’s WP Tavern interview with Automattic code wrangler Konstantin Obenland. Find out how it’s meant to be used in theme development and how to contribute to the project, and explore a sampling of the outstanding sites built using Underscores.