Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback Featured Image #32447

Closed
maharzan opened this issue Jun 4, 2021 · 10 comments
Closed

Fallback Featured Image #32447

maharzan opened this issue Jun 4, 2021 · 10 comments
Labels
[Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [Type] Enhancement A suggestion for improvement.

Comments

@maharzan
Copy link

maharzan commented Jun 4, 2021

I have been trying to learn making block base themes and encountered a simple issue. I need to show a default fallback image if the posts have no featured images.

Obviously, with older/current method, we can do it something like this

<?php if ( has_post_thumbnail() ) {
 the_post_thumbnail();
 } else { ?>
 <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
 <?php } ?>

But with blocks and new html templates, I can only do

<!-- wp:post-featured-image {"isLink":true} /-->

Further digging down the files, I saw this file and line was extracting the featured image and I didn't see any hooks in there so I can try to replace it in functions.php

https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/post-featured-image/index.php#L24

Is this possible in any other way? If not, I guess it would be really nice to have a hook in there so we can apply a default featured image on new block based themes.

@paaljoachim
Copy link
Contributor

Hi @maharzan Chandra

I will call this an associated issue:
There has been some explorations here (linking to my comment):
#13795 (comment)
Where I explored setting the first image in the post/page as a featured image.

@paaljoachim paaljoachim added the [Type] Enhancement A suggestion for improvement. label Jun 4, 2021
@maharzan
Copy link
Author

maharzan commented Jun 4, 2021

I wonder why such simple things has become so complex nowadays..

@paaljoachim
Copy link
Contributor

We should think out a simpler solution and present it..:)

@justintadlock
Copy link
Contributor

For now, you could just use the post_thumbnail_html hook: https://developer.wordpress.org/reference/hooks/post_thumbnail_html/

@altivero
Copy link

altivero commented Jun 4, 2021

I think this should be the default setting as outlined in the issue I created about this here: #31849

@maharzan
Copy link
Author

maharzan commented Jun 5, 2021

For now, you could just use the post_thumbnail_html hook: https://developer.wordpress.org/reference/hooks/post_thumbnail_html/

Thanks @justintadlock. That seems to do the trick.

@ntsekouras
Copy link
Contributor

Thanks for reporting @maharzan and @justintadlock for pointing out the proper filter: #32447 (comment).

I'll close this now as related discussions here are tracked in separate issues.

@paaljoachim
Copy link
Contributor

paaljoachim commented May 3, 2022

Hey Nik @ntsekouras

I believe we might need to open this issue again, as the associated issue:
Add option to set as feature image to image / cover block - has been closed.
#13795

I believe there still are aspects needed to be looked closer at in both issues.

@paaljoachim paaljoachim reopened this May 4, 2022
@paaljoachim
Copy link
Contributor

I went ahead and reopened this issue.

@skorasaurus
Copy link
Member

While triaging, I found this also to be reported at #34865 with a bit of discussion there as well so I am closing this issue. Please follow that issue for further updates and to share any opinions that you have.

@skorasaurus skorasaurus added the [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed label May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

6 participants