Have you heard of WordPress $content_width?

The WordPress theme check is a great plugin. For those who haven’t seen it it’s a way to check that you theme covers all of the functionality required to be added to the WordPress.org theme directory. I have been using this plugin to help me test the themes that I am creating on Pro Theme Design.

It covers a surprisingly wide array of tests, making sure that you don’t have any errors, and that you support all the most important elements of WordPress (to provide maximum bang for buck).

One of the features it checks for is use of the $content_width variable – and this isn’t something I have ever seen used or mentioned, so I thought I would do a bit of research into it.

$content_width;

So, it turns out, that the usage is simple. The variable is a global variable that is used to set the width of the content on the site. The only thing this affects is the images uploaded to the image uploader, and videos embedded with the video shortcodes. Setting the variable correctly means that the images will have a resized version that fits perfectly within your content – so it’s definitely a nice thing to include.

The recommended implementation is to add the following to your functions.php file in the theme root.

if ( ! isset( $content_width ) ) $content_width = 900;

Personally I would like to see this variable filterable so that I don’t have to add some random floating code in my functions.php

If you want to try the WordPress Theme Check plugin for yourself then you can download it from WordPress.org.

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

13 May 2010

6 Tips to Build Better WordPress Themes

If you want to make WordPress themes, for clients, to release for free or to sell, then there are a lot of factors you need to take into consideration. Below are some hints and tips that should help ease your...
17 Oct 2012

WordPress Social Network Aggregation

I really like the idea of a Tumblog – and even have one on Tumblr.com – but I don’t promote it anywhere. Conceptually it’s great – but I don’t like not having control over my content.What I would really like...
27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...
01 Apr 2015

The State of WordPress Themes #wcldn

I recently spoke on a panel at WordCamp London 2015e. Lance – who used to be the Theme Team lead at WordPress.com – asked me if I wanted to speak on a panel with him at WordCamp London 2015. I’ve...
08 Aug 2013

The Death of WordPress Theme Frameworks

WordPress theme frameworks are on their way out. They’re dying a slow death. At least that’s what I think.Nathan Rice recently wrote an article with his thoughts about theme frameworks – in defense of them – however he clearly has...
29 Mar 2009

The future of WordPress themes

A couple of weeks ago there was quite a lot of talk within the WordPress themes community about the future of WordPress. Ian Stewart started it, and then it spread around the blogosphere… so I thought I’d offer my rather...