102 PART II • Designing and Developing WordPress Themes
Figure 4-9: The Media Settings in the WordPress admin isn’t the only way to control image width.
This is where $content_width comes in. It sets the width for large-sized images. Remem-
ber, when uploading an image to WordPress, you get a total of four images: the ones listed on
the admin page and the original one. And with $content_width, the large image will fit
perfectly with your theme.
The most important usage for this setting however, is oEmbed. When you paste a YouTube or
Vimeo URL, WordPress will automatically embed that video. This is done with an open
format called oEmbed. The width for this embed, which will also control the height of the
video because it scales, comes from $content_width. There are several oEmbed services,
and not all of them rely on this setting, but it’s important nonetheless.
It is easy to set the width. Just put this snippet in functions.php (within the PHP tags of
course):
$content_width = 580;
580 is the width in pixels, so you need to change that to whatever is the maximum width for
content in your theme.
INSERTING PROMOTIONS WITH FUNCTIONS.PHP
A lot of blogs and sites show promotional elements after the post, usually to get people to
subscribe to the RSS feed. This is easily done in the theme’s template files, but it can also be
handled by your functions.php file and some action hookery.