treehouse : what would you like to learn today?
Web Design Web Development iOS Development

$content_width and RWD

  • I'm designing a responsive theme for WordPress and I don't know what to do about the $content_width variable. as the width would depend on the viewport. Does anybody know what I should do?

  • I believe, and I may be wrong, $content_width in Wordpress is a way to set the max width of images.

    If you're using responsive design techniques, what you could do is simply override the standard image width/height markup using CSS.

    For example, setting a max-width of a particular amount, or indeed 100% - with height set to auto, that way you know that the images will never expand beyond their container, so when downsizing they will adjust to fit automagically.

  • Yes Andy, that's exactly what I do with images. I too have read "rumours" of it being used to stop images overflowing, but it is so poorly documented. I thought I could just leave it out so I ran the theme-tester plugin after removing the:

    if ( !isset( $content_width ) ) $content_width = 610;

    and it threw up an error stating that the line was required so I don't know what to do now.

  • @lenzjo, I may be misunderstanding what you're asking, but if you want to remove the width and height attributes from images on wordpress, this snippet might help

  • Thx ChrisP, but I'm already doing that. It's the $content_width variable and setting (or not) it's value.