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?
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.
Somewhat related: I don’t know if it’s reasonable to use
$content_width
if you plan on developing a theme that allows flexible design options. For example, let’s say that your#content
will be set to512px
if a user has sidebar widgets active and768px
if a user has no sidebar widgets active. I see no reason why CSS isn’t enough to handle image overflows in main content areas:This CSS works perfectly fine to not only a) protect against image overflows into adjacent DIVs but also b) properly vertically resize images when they are shrunken down to fit into
#content
. Maybe I’m missing something but I don’t quite get the need for$content_width
.$content_width
is used for limit the image width in post content. It will overwrite setting in Media section forlarge
size. If you define this variable infunctions.php
file, then the width oflarge
size of uploaded image will be$content_width
.Here is a post about this.