-
aesthetik
Thanks @Ying.
But if I remove the GB image block, then the swap between featured image and video wont’ work. I tried to add the wordpress default featured image block to my element and then added the css class referenced in the code above. Didn’t work. Still shows the featured image is i disable.
Is this not possible in this situation?
-
Alvind
The snippet uses the
custom-featured-image
class for the featured image block, but when I inspect the page, that class isn’t present on the featured image. Did you modify the class name in the snippet? -
aesthetik
Yes, I did change it, only the names of the classes. I have reverted back to exactly what we’ve used above in the code snippets. Still the same issue.
Added some more info in private note.
-
Alvind
Unfortunately, the Disable Elements option does not affect featured images added via blocks or content templates—it only hides the featured image when using the theme’s default post layout.
In this case, we can use custom CSS to hide the featured image for the specific post you want. Would that approach work for you?
-
aesthetik
Worth a try!
Or, if you have a better solution to replace the featured image with a video if its added to a post? Either via ACF field or other option?
Open to all solutions.
-
Alvind
For a CSS solution, you can try this:
1. Create a new Hook element.
2. Add this snippet to the hook editor:<style> .custom-featured-image { display: none; } </style>
3. Set the Hook to
wp_head
.
4. In the Display Rules, set the location to Post and specify the posts where you want to hide the featured image.Or, if you have a better solution to replace the featured image with a video if its added to a post? Either via ACF field or other option?
So, if you want to explore this solution, the video is stored in a separate custom field, not the same field used to show when the featured image is not set. Is that correct?
-
aesthetik
OK, this hook works and definitely a solution for this. However, my site has hundreds of posts and having to ask non-admins to go into the hook element and update the display element may not be ideal.
The initial setup of the featured image, and swapping it if a video is added works flawlessly thanks to your team’s help. Guess the only flaw in the solution is if we wanted to not show a featured image/video in that place.
My ideal workflow would allow a user who is making a post to add a featured image (for thumbnail purposes) and if relevant, a video that would replace the featured image in its place on the post by entering a youtube URL in the ACF form at the bottom of the post editor. Or hide the featured image/video completely. 2/3 are done, I just can’t seem to turn off featured image with GeneratePress/Blocks Pro if one is not wanted on the edit post page.
If this isn’t possible with GeneratePress/Blocks that fine. I appreciate all the help this far. I just wanted to explore this element before I looked to other plugins/solutions.
-
Alvind
I just can’t seem to turn off featured image with GeneratePress/Blocks Pro if one is not wanted on the edit post page.
Let’s take a more structured approach by using a custom field to control whether the featured image is displayed. This way, users won’t need to manually edit the element to add each post inside the display rules location.
Edit the Post Field field group and add a new Select field named Hide Featured Image. Under Choices, add yes and no, set the Default Value to no, and change the Return Format to Value.
Add the following PHP snippet:
function hide_featured_image_block_on_singles() { // Only apply on single post pages if (is_single()) { global $post; // Check if we should hide featured image for this post $hide_featured = get_post_meta($post->ID, 'hide_featured_image', true); if (strtolower($hide_featured) == 'yes') { // Add custom CSS to hide featured image blocks ?> <style> body.single-post.postid-<?php echo $post->ID; ?> .custom-featured-image { display: none !important; } </style> <?php } } } add_action('wp_head', 'hide_featured_image_block_on_singles');
Now, whenever users create a post, they can select yes or no from the custom field to control the visibility of the featured image without modifying any elements manually.
-
aesthetik
Thanks @Alvind.
I’ve tried this and get the select feature to show up on posts, but changing it from No to Yes doesn’t effect the featured image. I’m using the generateblocks image block for the featured image. Is that an issue?
-
Alvind
I’ve made slight changes to the snippet above. Try replacing the previous snippet with the updated one.
-
aesthetik
Thanks @Alvind, got the featured image to disappear now when selected, but my featured video fucntionality is broken now.
I’ve posted links in the private info section for your reference.
-
Alvind
Check your shortcode snippet for the featured video. You’re still using
custom-story-video
as the custom field name, but it should befeatured_video
. -
aesthetik
Thanks, I tried to update, but still can’t seem to get it to load. I’ve checked my shortcode snippet and using “featured_video” now. Cleared cache but still can’t get it to appear.
-
Alvind
I’ve made a slight adjustment to your snippet that dynamically displays either an image or a video, and it seems to be working now. Can you check?
-
aesthetik
it works!
Thank you so much! Everything seems to be working now.
-
Alvind
Glad to hear that! 🙂
- You must be logged in to reply to this topic.