From 7a8e17d50a630a6487e82c8fea31f73c3d82b6a9 Mon Sep 17 00:00:00 2001 From: "David A. Kennedy" Date: Thu, 22 Dec 2016 23:24:44 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@39635 git-svn-id: http://core.svn.wordpress.org/trunk@39575 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../themes/twentyseventeen/functions.php | 24 +++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/wp-content/themes/twentyseventeen/functions.php b/wp-content/themes/twentyseventeen/functions.php index caa5f51c89..d68dc51c8a 100644 --- a/wp-content/themes/twentyseventeen/functions.php +++ b/wp-content/themes/twentyseventeen/functions.php @@ -55,6 +55,9 @@ function twentyseventeen_setup() { add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true ); + // Set the default content width. + $GLOBALS['content_width'] = 525; + // This theme uses wp_nav_menu() in two locations. register_nav_menus( array( 'top' => __( 'Top Menu', 'twentyseventeen' ), @@ -199,10 +202,23 @@ add_action( 'after_setup_theme', 'twentyseventeen_setup' ); */ function twentyseventeen_content_width() { - $content_width = 700; + $content_width = $GLOBALS['content_width']; - if ( twentyseventeen_is_frontpage() ) { - $content_width = 1120; + // Get layout. + $page_layout = get_theme_mod( 'page_layout' ); + + // Check if layout is one column. + if ( 'one-column' === $page_layout ) { + if ( twentyseventeen_is_frontpage() ) { + $content_width = 644; + } elseif ( is_page() ) { + $content_width = 740; + } + } + + // Check if is single post and there is no sidebar. + if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) { + $content_width = 740; } /** @@ -214,7 +230,7 @@ function twentyseventeen_content_width() { */ $GLOBALS['content_width'] = apply_filters( 'twentyseventeen_content_width', $content_width ); } -add_action( 'after_setup_theme', 'twentyseventeen_content_width', 0 ); +add_action( 'template_redirect', 'twentyseventeen_content_width', 0 ); /** * Register custom fonts. diff --git a/wp-includes/version.php b/wp-includes/version.php index b7375d7646..52641adad4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-39626'; +$wp_version = '4.8-alpha-39635'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.