Make WordPress Core

Changeset 39650


Ignore:
Timestamp:
12/30/2016 05:46:58 AM (8 years ago)
Author:
dd32
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.
Merges [39635] to the 4.7 branch.
Fixes #39272.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-content/themes/twentyseventeen/functions.php

    r39575 r39650  
    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.