$content_width in “twentyfifteen.1.4” WP Default tHEME

if ( ! isset( $content_width ) ) {
    $content_width = 660;
}

The above mentioned code exist in wordpress Default Theme Functions.php on line#33

My Question: $content_width

It looks like a global variable defined somewhere in core files in wordpress?
$content_width=660;

what is 660 is it in pixel. Actually which content width is this setting? The current theme has this anatomy: sidebar and content area.

Or it is effecting post and pages types?

1
1

$content_width is one of the dark magic global variables wordpress uses. The value refers to the width in pixels of the area in which the post content is being displayed in a post page. It is expected to be set by themes.

The reason for the

if ( ! isset( $content_width ) ) {

is to let child themes to override this value by defining it in their functions.php file

Why is it needed? There might be other needs, but one place in which it is needed is where the oEmbed protocol is being used to retrieve some HTML (usually an iframe) from a 3rd party service. For example a youtube video sharing iframe that is retrieved based on a youtube URL.

As part of the oEmbed protocol you can let the 3rd party server know the dimensions of area it may fill, and wordpress core needs to assume something that will make some sense just based on the youtube url, and it will use the single post content width – the $content_width variable.

Looking now at the 4.4 code I see that there are more uses, the native video shortcode, getting images in the correct size for the editor and more.

BTW the default is 500

Leave a Comment