• Resolved seanpaulfx

    (@seanpaulfx)


    Hello, I am having the problem that the child post does not have featured image then in schema “ImageObject” will not appear.

    Before that I added the code below to display the images shared on social networks

    function add_parent_post_image( $manager ) {
    	if ( is_singular( 'life' ) ) {
    	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' );

    Next problem I add the code below to show the video schema but the “‘inLanguage’ => ‘en-PH’,” section automatically switches to “‘inLanguage’ => ‘en-US'”.
    How can I fix it.

    add_filter( 'rank_math/json_ld', function( $json_ld, $json ) {
        
      if ( is_singular() && ! isset( $json_ld['richSnippet'] ) ) {
        $post_id = $json->post_id;
          $json_ld['richSnippet'] = [
            '@context'         => 'https://schema.org',
            '@type'            => 'VideoObject',
            'name'             => $json->parts['title'],
            'description'      => $json->parts['desc'],
            'uploadDate'       => get_post_meta( $post_id, '_meta_key', true ),
            'duration'         => get_post_meta( $post_id, '_meta_key', true ),
            'contentUrl'       => get_post_meta( $post_id, '_meta_key', true ),
            'embedUrl'         => get_post_meta( $post_id, '_meta_key', true ),
            'interactionCount' => get_post_meta( $post_id, '_meta_key', true ),
            'thumbnailUrl'     => get_post_meta( $post_id, '_meta_key', true ),
    	'inLanguage'  => 'en-PH',
    	'subtitleLanguage' => 'en-US',
          ];
      }
    
      return $json_ld;
    }, 11, 2);
Viewing 1 replies (of 1 total)
  • Plugin Author Rank Math

    (@rankmath)

    Hello @seanpaulfx

    Thank you for your message.

    The first code to add the parent post image in the child post in opengraph tags is correct and it should work fine.

    For the 2nd issue, the Schema one, please use a higher priority for the hook.

    add_filter( 'rank_math/json_ld', function( $json_ld, $json ) {
       //Add your code here.
    }, 9999, 2 );

    This should fix the language issue.

    Hope that helps.

Viewing 1 replies (of 1 total)
  • The topic ‘RichSnippet (ImageObject and VideoObject)’ is closed to new replies.