0

I've read many answers to the problem of modifying TwentySeventeen's content width, but this one aspect is eluding me.

I have the following in my child theme's functions.php

function childtheme_content_width( $content_width ) {
    echo '<script>console.log("$content_width was ' . $content_width . '")</script>';
    if ( is_single() || is_admin() ) {
        $content_width = 800;
    }
    echo '<script>console.log("$content_width now ' . $content_width . '")</script>';
    return $content_width;
}
add_filter( 'twentyseventeen_content_width', 'childtheme_content_width', 11);

function my_custom_sizes( $sizes ) {
    return array_merge( $sizes, array(
    'post-perfect' => __( 'Full post width' ),
    ) );
}
add_filter( 'image_size_names_choose', 'my_custom_sizes' );

function add_new_image_size() {
    add_image_size ( 'post-perfect', 800, 800);
}
add_action( 'after_setup_theme', 'add_new_image_size', 11 );

According to my reading, that should allow for 800 pixel wide content in single pages (and admin) and add a new image size "Full post width" which should be 800 pixels wide.

However, while I can prove from the console that the width is correctly set from 525 to 800 when viewing a single post (and embeds expand to fill this), when I am in the editor the code does not run (there is no output from the console.log) and I assume this is the reason why the "Full post width" image size shows up with a width of 525 in the drop-down list of sizes.

What am I missing to make this change to $content_width work during editing and therefore (I assume) allow for 800-pixel wide images?

  • 2
    Image sizes don't apply retroactively. You'll need to regenerate them for your size to be available. – Jacob Peattie Mar 20 '18 at 8:29
  • Thanks, I had pondered that, but when I add a brand new image it is still showing the Full post width size as 525. – zkarj Mar 21 '18 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.