From 213d196d669ecedcabf5a0fe422a65cdc6094e5c Mon Sep 17 00:00:00 2001 From: "David A. Kennedy" Date: Thu, 22 Dec 2016 23:23:23 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@39635 602fd350-edb4-49c9-b593-d223f7449a82 --- .../themes/twentyseventeen/functions.php | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/wp-content/themes/twentyseventeen/functions.php b/src/wp-content/themes/twentyseventeen/functions.php index caa5f51c89..d68dc51c8a 100644 --- a/src/wp-content/themes/twentyseventeen/functions.php +++ b/src/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.