WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/22/2016 11:23:23 PM (17 months ago)
Author:
davidakennedy
Message:

Twenty Seventeen: Fix incorrect $content_width value in theme

This addresses a major bug. Incorrectly setting the $content_width causes media embeds to end up with the wrong aspect ratio, among other issues. This fix uses template_redirect, to ensure conditional theme tags can be used. It also defines a default value at after_theme_setup so that plugins have something to work with at init.

Props sstoqnov, laurelfulford, obenland.

Fixes #39272.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyseventeen/functions.php

    r39618 r39635  
    5555
    5656    add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
     57
     58    // Set the default content width.
     59    $GLOBALS['content_width'] = 525;
    5760
    5861    // This theme uses wp_nav_menu() in two locations.
     
    200203function twentyseventeen_content_width() {
    201204
    202     $content_width = 700;
    203 
    204     if ( twentyseventeen_is_frontpage() ) {
    205         $content_width = 1120;
     205    $content_width = $GLOBALS['content_width'];
     206
     207    // Get layout.
     208    $page_layout = get_theme_mod( 'page_layout' );
     209
     210    // Check if layout is one column.
     211    if ( 'one-column' === $page_layout ) {
     212        if ( twentyseventeen_is_frontpage() ) {
     213            $content_width = 644;
     214        } elseif ( is_page() ) {
     215            $content_width = 740;
     216        }
     217    }
     218
     219    // Check if is single post and there is no sidebar.
     220    if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) {
     221        $content_width = 740;
    206222    }
    207223
     
    215231    $GLOBALS['content_width'] = apply_filters( 'twentyseventeen_content_width', $content_width );
    216232}
    217 add_action( 'after_setup_theme', 'twentyseventeen_content_width', 0 );
     233add_action( 'template_redirect', 'twentyseventeen_content_width', 0 );
    218234
    219235/**
Note: See TracChangeset for help on using the changeset viewer.