Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Searching here I've found two questions related and at the time, this wasn't possible.

how to create a conditional content_width for a wordpress theme?

And an alternative way via CSS described by Philip Arthur Moore (the code is also on Codex): What is the role and history of the $content_width global variable?

Since the questions mentioned are a little old, my question is if the versions released after mid 2013 have improved the function so we could use it with conditionals.

share|improve this question

1 Answer 1

As of now there is no direct way to conditionally set content_width.But we can do this using template_redirect hook and changing the global content_width.This is done in Twenty Fourteen Theme.Following is the code.

/**
 * Adjust content_width value for image attachment template.
 *
 * @since Twenty Fourteen 1.0
 */
function twentyfourteen_content_width() {
    if ( is_attachment() && wp_attachment_is_image() ) {
        $GLOBALS['content_width'] = 810;
    }
}
add_action( 'template_redirect', 'twentyfourteen_content_width' );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.