What is the role and history of the $content_width global variable?

I just stumbled over a global variable called $content_width. It was new to me, so far I could see that it’s used in themes, both the standard twenty ten one and third party ones.

It looks like that it contains the width of the content area in pixels. Since global variables are not documented in the codex, I had trouble finding information about it.

When was the $content_width global variable introduced and for what reason? Is there a ticket related to it?

3

I believe it was added back on WordPress 2.6 (maybe 2.5). It’s there to allow you to set a maximum width on images being displayed as content in your theme. E.g. If your main content area is only 475px wide, you could set $content_width = 450 to make sure your image doesn’t break out of your main content area.

Leave a Comment