[Resolved] post title Location

Home Forums Support [Resolved] post title Location

Home Forums Support post title Location

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1182524
    Ruth Kijner

    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.

    #1182729
    David
    Staff
    Customer Support

    Hi there,

    do you want your sidebar below your Post Title / Meta and Featured Image ? Let me know

    #1182766
    Ruth Kijner

    Hello David,
    Thank you for the fast reply.
    I want the side bar below Post Title / Meta and Featured Image.

    Thanks!

    #1183261
    David
    Staff
    Customer Support

    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]

    #1183660
    Ruth Kijner

    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

    #1183671
    David
    Staff
    Customer Support

    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

    #1184093
    Ruth Kijner

    now its perfect, thank you so much!

    #1184404
    David
    Staff
    Customer Support

    Glad to be of help

    #2034006
    johnaps

    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!

    #2034393
    Ying
    Staff
    Customer Support

    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 πŸ™‚

    #2037162
    johnaps

    I think its perfect! Thank you! πŸ™‚

    #2037508
    Ying
    Staff
    Customer Support

    You are welcome πŸ™‚

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.