Archived topic
post title Location
11 replies · Started by Ruth Kijner on March 2, 2020
Hello,
At this point, I use the Single Posts element configuration. And I love how the featured image is displayed.
But I don't want the post title, post date, and post author inside the featured image.
My question is it possible to locate the post title, post date outside and on top of the featured image.
example. https://yoast.com/measure-social-media-efforts/
Thank you so much in advance.
Hi there,
do you want your sidebar below your Post Title / Meta and Featured Image ? Let me know
Hello David,
Thank you for the fast reply.
I want the side bar below Post Title / Meta and Featured Image.
Thanks!
First off add this PHP snippet to your site:
function db_feat_img_shortcode() {
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large', false );
return '<img src="' . $img_src[0] . '"/>';
}
add_shortcode( 'db_feat_img', 'db_feat_img_shortcode' );
https://docs.generatepress.com/article/adding-php/
Now edit the Header Element you have assigned to your Posts, and remove the featured image background, and remove the padding. Below your HTML for the title and post date add this Shortcode:
[db_feat_img]
Hello David,
I followed all the steps, and the result is almost perfect.
Now the post title, post date, and post author are separated from the image, that is exactly what I wanted.
But the image is different -please see the screenshot before the PHP code https://www.perfectinvest.net/before_php/
please see the screenshot after the PHP code
https://www.perfectinvest.net/after_php/
So my question is it possible to keep the layout of the image before the changes.
Thank you in advance
In this line of the code:
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large', false );
change large to full
now its perfect, thank you so much!
Glad to be of help
Hello David, is there a way for this function (#1183261) to also fetch the image's alt text (that is coming from what we wrote in the wordpress image library)?
Cause i am using this code and it doesn't output an alt text unfortunately even though the images have alt text in my wordpress library!
Hi Johnaps,
Give this snippet a try:
function yh_feat_img_shortcode() {
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large', false );
$image_id = get_post_thumbnail_id( $post->ID);
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);
return '<img src="' . $img_src[0] . '" alt="'. $image_alt. '"/>';
echo $image_alt;
}
add_shortcode( 'yh_feat_img', 'yh_feat_img_shortcode' );
Let me know if this helps :)
I think its perfect! Thank you! :)
You are welcome :)