• Resolved hellodollys

    (@hellodollys)


    Hello, I am having a problem with images.
    I have 2 post types linked together
    Post Type: Post And List.
    In the post type (List) I do not post featured images, is there a way for me to get images from the postype post instead?

    Hope you understand what I mean.

    • This topic was modified 6 years, 6 months ago by hellodollys.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Rank Math SEO

    (@rankmath)

    Hello @hellodollys

    Thank you for contacting the support.

    Can you please tell us how did you link them so we can help you better?

    A screencast would be helpful.

    Looking forward to helping you.

    Thread Starter hellodollys

    (@hellodollys)

    Hello, I have currently selected the default featured image for all pages that do not have featured images. I then used this code instead. Do you have any other solutions?

    add_filter( "rank_math/opengraph/facebook/image", function( $attachment_url ) {
    global $post;
    $img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->post_parent ), 'thumbnail' );
    $img = $img[0];
    	if ( is_singular( 'list' ) ) {
    		$attachment_url = $img;
    	}
    	return $attachment_url;
    });
    
    add_filter( "rank_math/opengraph/twitter/image", function( $attachment_url ) {
    global $post;
    $img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->post_parent ), 'thumbnail' );
    $img = $img[0];
    	if ( is_singular( 'list' ) ) {
    		$attachment_url = $img;
    	}
    	return $attachment_url;
    });
    
    add_filter( 'rank_math/opengraph/image_sizes', function( $sizes ) {
    	if ( is_singular( 'list' ) ) {
    		$sizes = [ 'thumbnail' ];
    		return $sizes;
    	} else {
    		return $sizes;
    	}
    });

    I want to ask one more question, Is there any way to turn all previous articles into videos? As the image shows below, manual replacement is time consuming because of too many posts.

    https://imgur.com/fNP20ny

    • This reply was modified 6 years, 6 months ago by hellodollys.
    Plugin Author Rank Math SEO

    (@rankmath)

    Hello @hellodollys

    The code which you added is correct but is not needed as long as the plugin’s working fine.

    This is how we show the image on the link shared on a social media website. Here’s the priority:
    Image set in the Social tab of the Rank Math plugin
    If nothing’s set there, then
    The featured image of the article
    If nothing’s set there, then
    The first image inside the content
    If nothing’s found there, then
    The global image set in the General Settings of the Rank Math plugin

    Hope this clears the confusion and please let us know if it is not working for you as mentioned here.

    Looking forward to helping you. Thank you.

    Thread Starter hellodollys

    (@hellodollys)

    Is there any code for me to add images without going through the default featured image? I am having problem with image size with the above code. If I leave the code as below full size it will take the image size of the default featured image.

    add_filter( 'rank_math/opengraph/image_sizes', function( $sizes ) {
    	if ( is_singular( 'list' ) ) {
    		$sizes = [ 'full' ];
    		return $sizes;
    	} else {
    		return $sizes;
    	}
    });
    Plugin Author Rank Math SEO

    (@rankmath)

    Hello @hellodollys

    Please try with the following filter:

    function add_parent_post_image( $manager ) {
    	global $post;
    	$manager->add_image_by_id( get_post_thumbnail_id( $post->post_parent ) );
    }
    add_filter( 'rank_math/opengraph/facebook/add_images', 'add_parent_post_image' );
    add_filter( 'rank_math/opengraph/twitter/add_images', 'add_parent_post_image' );

    Let us know if that helps. Thank you.

    Plugin Author Rank Math SEO

    (@rankmath)

    Hello,

    Since we did not hear from you on this, we are assuming that the issue’s resolved.

    If that is not the case, please feel free to reply to this topic or open a new one.

    We are here to help.

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘og:image post parent’ is closed to new replies.