- This topic has 30 replies, 6 voices, and was last updated 4 years, 7 months ago by Leo.
-
AuthorPosts
-
July 11, 2017 at 11:37 pm #347978TomLead DeveloperLead Developer
Yes, if you’re using a global page header for all single posts, you won’t be able to use only the featured image inside one of your posts. The featured images are used in the global page header. In this case, you would need to use custom code to insert the featured image (not a big deal).
Your code to add the featured image would look something like this:
add_action( 'generate_before_content', 'tu_add_featured_image' ); function tu_add_featured_image() { if ( is_singular( 'post' ) && has_post_thumbnail() ) { the_post_thumbnail(); } }
July 13, 2017 at 1:24 am #348636PeterYep, added that code and now the featured image shows up under the page header.
http://playground.codebastler.com/first-test-post-with-gp-premium-1-4-alpha/So as a beta-tester some last thoughts:
– I am using WP since 6 years. For me the featured image was always perceived as part of the content and not so much of the header. Especially when there were galleries, then it was the the most important pic to select as featured image. which will then be used in category & tagged pages.
-Maybe it should be more clarified with the new page header part, what is for pages & posts globally and what is singularly.
For example I can click “featured image”in the page header part and it is not really obvious, that it is only THAT featured image, that will be used globally. In the beginning of testing I assumed, that it WILL BE the featured image of each page or post.– Eventually one can add a select field in the page header part for pages & posts > “use featured image globally/singularly” – and if singularly then the custom code from you will be hooked.
Cheers
P.July 14, 2017 at 12:43 am #349237TomLead DeveloperLead DeveloperThank you! I really appreciate your feedback and suggestions! 🙂
September 9, 2017 at 1:42 am #382153Chad BiggsUsing a shortcode is another option. You can make this a plugin or add it to your functions.
add_shortcode('thumbnail', 'thumbnail_in_content'); function thumbnail_in_content($atts) { global $post; return get_the_post_thumbnail($post->ID); }
And then use [thumbnail] to call the image.
September 9, 2017 at 10:31 am #382387TomLead DeveloperLead DeveloperThanks, Chad. Good solution 🙂
June 15, 2018 at 11:09 am #601000KevinCan this be added via GP Hooks?
June 15, 2018 at 12:25 pm #601056KevinWell, answered my own question. I was able to use it in GP Hooks, but had to wrap it with the <?php ?>.
One thing I noticed was that this makes the Customize > Layout > Blog: Feature Image: Single Post settings irrelevant.
Also, you have to place the code in the GP Hooks block where you want the featured image to be displayed.
Edit:: Found this did not work when I tried using it in the “After Entry Title” section in GP Hooks. How would I be able to use it there?
June 15, 2018 at 8:25 pm #601227LeoStaffCustomer SupportSorry..what exactly are you trying to do?
Feel free to open a new topic 🙂
June 15, 2018 at 8:32 pm #601228KevinSorry, I was asking about using the code from Tom above in GP Hooks to add the Featured Image to the post when you are using the Header module. I guess I should have started with that in my post.
From the searching I did, this topic had the easiest solution to implement.
June 15, 2018 at 8:34 pm #601229LeoStaffCustomer SupportTo use the page header with featured image?
Try this snippet: https://generatepress.com/forums/topic/suggestion-page-header-for-pages-posts/page/2/#post-347978
Let me know 🙂
June 15, 2018 at 8:37 pm #601234KevinThat’s what I used. I was actually asking if that code snippet could be used with GP Hooks, and how.
This is what I found:
Well, answered my own question. I was able to use it in GP Hooks, but had to wrap it with the <?php ?>.
One thing I noticed was that this makes the Customize > Layout > Blog: Feature Image: Single Post settings irrelevant.
Also, you have to place the code in the GP Hooks block where you want the featured image to be displayed.
Edit:: Found this did not work when I tried using it in the “After Entry Title” section in GP Hooks. How would I be able to use it there?
Is there a better way than this?
June 15, 2018 at 8:48 pm #601243LeoStaffCustomer SupportTry this snippet:
add_action( 'generate_after_entry_title', 'tu_add_featured_image' ); function tu_add_featured_image() { if ( is_singular( 'post' ) && has_post_thumbnail() ) { the_post_thumbnail(); } }
June 15, 2018 at 8:49 pm #601244KevinThanks!
June 16, 2018 at 10:23 am #601604LeoStaffCustomer SupportNo problem!
September 4, 2019 at 1:09 am #1000604antoineHello,
Could you tell me what is the best way to insert this code and cusomize featured image.
add_action( ‘generate_before_content’, ‘tu_add_featured_image’ );
function tu_add_featured_image() {
if ( is_singular( ‘post’ ) && has_post_thumbnail() ) {
the_post_thumbnail();
}
}Do I need to install Code Snippets?
Thank youn
-
AuthorPosts
- You must be logged in to reply to this topic.