Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Why We should set the variable $content_width in wordpress theme functions ?

user-image
Question ajoutée par Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
Date de publication: 2017/03/04
Abid Hussain Safi
par Abid Hussain Safi , Web Developer /Digital Solution Specialist , Hamptons International Dubai LLC

Using this feature you can set the maximum allowed width for any content in the theme, like oEmbeds and images added to posts.

 

Themes need to specify the $content_width variable in the function.php file, like so:

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

Bilal Hassan
par Bilal Hassan , Web developer , Ace Company

$content_width is a theme feature using this feature you can set the maximum allowed width for any content in the theme, like oEmbeds and images added to posts.

Kamal Hasija
par Kamal Hasija , Web Developer , The Brihaspati Infotech Pvt. Ltd.

By using this you can set the maximum allowed width for any content in the theme, like oEmbeds  and images added to posts.

Using this theme feature, WordPress can scale oEmbed code to a specific size (width) in the front-end, and insert large images without breaking the main content area. Also, using this feature you lay the ground for other plugins to perfectly integrate with any theme, since plugins can access the value stored in $content_width.

 

if ( ! isset( $content_width ) ) { $content_width = 600; }And @Adel Ezat Fawzy Ellozy thanks for the invitation Sir!!!Have a nice day,Regards,

AHMAD ALSHATANAWI
par AHMAD ALSHATANAWI , WEB MARKETING & SEO SPECIALIST , Creativo GBM

  1. The $content_width global variable was introduced in WordPress 2.6. ...
  2. It is a theme feature which helps us to control our content width for images, videos and embeds. ...
  3. To set the value for it, you must declare it as a global variable.

alaa liswe
par alaa liswe , ِAdministrative Assistant , Arab Open University

Content Width is a theme feature, first introduced in Version 2.6. Using this feature you can set the maximum allowed width for any content in the theme, like oEmbeds and images added to posts.

Using this theme feature, WordPress can scale oEmbed code to a specific size (width) in the front-end, and insert large images without breaking the main content area. Also, using this feature you lay the ground for other plugins to perfectly integrate with any theme, since plugins can access the value stored in $content_width.

Contents Adding Theme Support

Since Version 2.6, themes need to specify the $content_width variable in the functions.php file, like so:

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

It's also recommended to add the following CSS to your theme:

.size-auto, .size-full, .size-large, .size-medium, .size-thumbnail { max-width: 100%; height: auto; }

Notes: This variable is also used when displaying a pop-up selection in the Media Editor. If you have used the global $_wp_additional_image_sizes to allow a pop-up of your custom image sizes defined using add_image_size() then the $content_width will override the width specified by your add_image_size() function. (The array $_wp_additional_image_sizes is covered inget_intermediate_image_sizes() and basically holds the name/height/width of your various image sizes available.)

More Questions Like This