WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 20 months ago

#39281 reopened enhancement

Twenty Seventeen: header.php forces thumbnails on all post types

Reported by: justnorris Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Bundled Theme Keywords: has-patch
Focuses: ui, template Cc:
PR Number:

Description

My plugin has custom post type and custom 'single-post-type' views and doesn't utilize thumbnails in them. As a result layout appears broken, and there is nothing I can do to make the plugin compatible with Twentyseventeen.

I went to have a look how WooCommerce deals with this, and it turns out that there is this piece of code in the style of twentyseventeen:

.single-product .single-featured-image-header {
    display: none
}

While that does work, I don't think it's a solution. At the very least there has to be a filter to dynamically disable the thumbnail from header.php

Attachments (3)

39281.diff (1.7 KB) - added by JPry 3 years ago.
100p.png (1.0 MB) - added by justnorris 22 months ago.
100% zoom
50p.png (917.2 KB) - added by justnorris 22 months ago.
50% Zoom

Download all attachments as: .zip

Change History (12)

#1 @JPry
3 years ago

  • Focuses performance removed
  • Resolution set to worksforme
  • Status changed from new to closed

Hey @justnorris,

Thanks for taking the time to log a ticket here on Trac!

The twentyseventeen theme will only display a thumbnail when has_post_thumbnail() is true. As long there's no featured image set, then the theme won't try to display one. That means that there's no need to disable the thumbnail. Here's the relevant section of header.php:

        <?php
        // If a regular post or page, and not the front page, show the featured image.
        if ( has_post_thumbnail() && ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) ) :
                echo '<div class="single-featured-image-header">';
                the_post_thumbnail( 'twentyseventeen-featured-image' );
                echo '</div><!-- .single-featured-image-header -->';
        endif;
        ?>

It appears that WooCommerce is simply taking an extra precaution with hiding a possible featured image.

When registering your custom post type, you can also make sure that it does not support thumbnail in the supports parameter. This will ensure that users cannot even set a featured image to begin with.

#2 @justnorris
3 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Hey @JPry, thanks for the response. However, I have to disagree. My custom-post-type does support thumbnails, but I utilize them in a different way. Because of the current state of twentyseventeen I can't make the plugin compatible with the default WordPress theme. I think every WordPress plugin should look and feel great out of the box, with best practices intact. Currently that's impossible for me.

For my Photography Portfolio plugin - featured images are used in archives, but once a gallery is opened - a different set of images are used. I don't need to show the featured-image there, so at the moment, I have to resort to a hack like this one: https://github.com/justnorris/photography-portfolio/commit/d85b14b0232830fbceeb95eac10e5b196d10ae35

I'd really appreciate it if at least a filter was introduced. I can't be the only person on earth doing a custom view for a custom post type.

In any case - I think the header.php readability will too benefit from something like this:

<?php
        // If a regular post or page, and not the front page, show the featured image.
        if ( twentyseventeen_should_show_featured_image() ) :
                echo '<div class="single-featured-image-header">';
                the_post_thumbnail( 'twentyseventeen-featured-image' );
                echo '</div><!-- .single-featured-image-header -->';
        endif;

        // functions.php
        function twentyseventeen_should_show_featured_image() {
                return apply_filters( 'twentyseventeen_should_show_featured_image', ( has_post_thumbnail() && ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) ) );
        }
        

        ?>

Normally things like thumbnails belong to single.php, archive.php, etc., Twenty Seventeen does things a bit differently, that's alright, as long as it doesn't break things for others.

Last edited 3 years ago by justnorris (previous) (diff)

@JPry
3 years ago

#3 @JPry
3 years ago

  • Keywords has-patch added
  • Type changed from defect (bug) to enhancement

Replying to justnorris:

My custom-post-type does support thumbnails, but I utilize them in a different way.

That's different than what you said originally, which is why my original suggestion was to ensure your plugin wasn't providing support for thumbnails.

Having a filter certainly seems feasible to me.

#4 @justnorris
3 years ago

Sorry for not being clear the first time around. Thanks for the patch!

#5 @davidakennedy
3 years ago

  • Keywords reporter-feedback added

Hey @justnorris! Thanks for the report!

As a result layout appears broken, and there is nothing I can do to make the plugin compatible with Twentyseventeen.

Can you add some screenshots so I can see how it's broken? It would help determine the best path forward.

Also, thanks @JPry for the initial patch.

#6 @SergeyBiryukov
3 years ago

  • Summary changed from [twentyseventeen] header.php forces thumbnails on all post types to Twenty Seventeen: header.php forces thumbnails on all post types

@justnorris
22 months ago

100% zoom

@justnorris
22 months ago

50% Zoom

#7 @justnorris
22 months ago

@davidakennedy Ha, I didn't get a notification about the issue, and unfortunately the issue is still present 12 months later, even with the patch 😔

Here are the screenshots, I had to zoom out to 50% just to capture the general idea of the layout. It's a view of a single portfolio entry with a description and a gallery. The featured image is really unnecessary there.

#8 @justnorris
22 months ago

  • Keywords reporter-feedback removed

#9 @zkarj
20 months ago

Having just found this issue myself, I concur with the OP that header.php is not a logical place for the featured image unless that image is visually integrated into the header – e.g. replacing the header image. This does not appear to be the case with Twenty Seventeen.

In my case, I am developing a personal child theme so was able to override header.php and comment out the relevant block. It took me a while to figure out where the image was coming from!

Note: See TracTickets for help on using tickets.