Do you want to display the featured image below the post title on single posts in genesis?
It is so easy to do that.
In this short article, I will show you how to do it.
Display Featured Image Below Post Title in Genesis
You simply have to add this code to the functions.php
file.
add_action( 'genesis_before_entry_content', 'wg_featured_image_after_title'); function wg_featured_image_after_title() { if (!has_post_thumbnail()) { return; } if (is_single()) { printf('<figure><img src="%1s" alt="%2s"></figure>', genesis_get_image('format=url'), the_title_attribute('echo=0')); } }
So what I am doing here. Let me tell you in steps.
Step 1: Targeting Post Title
Firstly, I am targeting the post title using genesis hook named as genesis_before_entry_content
.
Step 2: Checking If post has Thumbnail
Then I check whether the current post has a thumbnail using has_post_thumbnail()
. If the post doesn’t have one, abort.
Step 3: Checking If I am on Single Post
This step includes checking the post; if it is posted, keep going; otherwise, don’t show.
Step 4: Printing the Output
Finally, the data is outputted using printf
. Inside the <figure>
I am adding img
.
If you have noticed, I am referencing image source using %1s
. genesis_get_image('format=url')
is used to get the URL of the image and the_title_attribute('echo=0')
is used for outputting alternative text.
Conclusion
I hope you loved this short tutorial, please do share and comment.
Leave a Reply