Opened 6 years ago
Last modified 5 years ago
#39281 reopened enhancement
Twenty Seventeen: header.php forces thumbnails on all post types
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.8 |
Component: | Bundled Theme | Keywords: | has-patch |
Focuses: | ui, template | Cc: |
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)
Change History (12)
#1
@
6 years ago
- Focuses performance removed
- Resolution set to worksforme
- Status changed from new to closed
#2
@
6 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.
#3
@
6 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.
#5
@
6 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
@
6 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
#7
@
5 years 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.
#9
@
5 years 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!
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 ofheader.php
: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 thesupports
parameter. This will ensure that users cannot even set a featured image to begin with.