- This topic has 9 replies, 4 voices, and was last updated 2 years, 8 months ago by Elvin.
-
AuthorPosts
-
February 1, 2021 at 7:59 pm #1642351Website Psychiatrist
Hello,
I’m experimenting with Header Elements, and I see that there are some template tags like {{post_date}} and {{post_terms.taxonomy}}.I’m looking to be able to use the featured image, and I got crazy and tried {{featured_image}} to no avail.
Is there a way to use featured image in the header elements, and I guess more useful would be a list of all of the available template tags … or are the 5 listed the only ones that exist?
Thanks!
BillFebruary 2, 2021 at 3:12 am #1642656ElvinStaffCustomer SupportHi there,
There’s no template tag for featured image as of this moment but here’s a suggestion:
We can make a shortcode for the purpose of displaying the featured image.
Try adding this PHP snippet:
add_shortcode( 'featured_image', function( ) { ob_start(); global $post; $featured_img_url = get_the_post_thumbnail_url($post->id); echo '<img class="page-hero-featured-image" src="'.$featured_img_url.'" alt="'.get_the_title($post->id).'"/>'; return ob_get_clean(); });
You can then use the shortcode
[featured_image]
to display the current post’s featured image with this. This would act like the{{featured_image}}
you were aiming for.February 2, 2021 at 8:37 pm #1643710Website PsychiatristAwesome! Thank you! That works. So are there no other template tags? Should we just create a shortcode if we’re needing something else than the 5 template tags that are displayed?
February 2, 2021 at 8:55 pm #1643715ElvinStaffCustomer SupportYou can check this brief documentation for all the other template tags:
https://docs.generatepress.com/article/header-element-template-tags/For the other ones, yes, you’ll have to create your own shortcode.
August 16, 2021 at 9:05 am #1897791WebmasterWhat’s the template tag to generate post content? Might you know? I tried
{{post_content}}
but that didn’t work. Hahaha…p.s. – if I create new block element, I see the dynamic tag but I don’t want to use this block.
August 16, 2021 at 9:58 am #1897855YingStaffCustomer SupportHi there,
I don’t think there’s a template tag for post content.
Any specific reason you don’t want to use dynamic content block?
August 16, 2021 at 8:58 pm #1898260WebmasterI want to created a no sidebar, merged header, full screen landing page with a parallax background image. I dabbled with the (new) Block element type but I believe it was to complex of a layout (but simple with old GP).
Maybe I’ll try it again… but I felt pretty sure this was not possible with my existing site.
It does seem odd, though, that there is no template tag for post content…seems like the code is already baked-into GP but not as easily accessible. To bad…
August 16, 2021 at 9:06 pm #1898264ElvinStaffCustomer SupportIf the main concern is having to display the_content within the header, we can make a quick shortcode for that.
Add this PHP snippet:
add_shortcode( 'post_content', function() { ob_start(); // Start your PHP below the_content(); // End your PHP above return ob_get_clean(); } );
Here’s how to add PHP snippets – https://docs.generatepress.com/article/adding-php/
With this, you can use the shortcode
[post_content]
to show the content of the post on the header. (or anywhere the shortcode is placed)August 17, 2021 at 6:00 pm #1899489WebmasterBravo!
August 17, 2021 at 8:35 pm #1899545ElvinStaffCustomer SupportHave you fully sorted it out? Let us know if you need further help. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.