• Resolved Andrey Sirota

    (@atoris)


    Hi!

    Can plugin auto-load information to fields of Video Snippet?

    So, for example, from WordPress Custom Field (youtube url) or first embed video in article?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @atoris

    Thank you for contacting the support.

    You can add the following filter to your theme’s functions.php file. The filter will only work on the frontend. We don’t have any filter or an option to autofill the values in admin area.

    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 ),
          ];
      }
    
      return $json_ld;
    }, 11, 2);

    Please stay advised that this code will only work on the posts where snippet was not selected.

    If you want to overwrite it in all posts then you will have to remove && ! isset( $json_ld['richSnippet'] ) from the if condition.

    Hope that helps. If you have any further question(s), please let us know.

    Thread Starter Andrey Sirota

    (@atoris)

    Do you plan to add automation process?

    So if I have YouTube URL or Custom Field(my case) with YouTube URL then your plugin could fetch all needed data (Like Yoast Video SEO).

    So in this case contentUrl will be empty and embedUrl will be generated from YouTube URL (https://stackoverflow.com/questions/15401445/change-youtube-url-to-embed-url-in-php)

    Hello @atoris

    Sorry to disappoint but that feature is unfortunately not available at this time.

    With that being said, there are existing feature requests, so I’ve added your vote to our internal suggestions lists. If your suggestions are something that we’re able to introduce, we’ll be sure to let you know.

    If you have any further question(s), please let us know. Thank you.
    ??????

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Video Rich Snippet – Automatically Filling’ is closed to new replies.