I’ve added the custom field in the admin, but the plugin still doesn’t recognise my YouTube video?

When using a custom field for your YouTube video, you probably only had to enter the ‘variable’ YouTube uses to show your video. There is no way our plugin knows what this code means without extra information.

To solve this, you can add the following code to you functions.php (Theme file).

/* Takes the youtube video ID stored in a custom field
 * and adds a full Youtube URL to the content to allow
 * the video SEO plugin to index it.
 * The video URL is added to the top of content to make
 * it override other video's in the post.
 * @param string $content the input content field.
 * @param array $vid the video array for the post.
 * @return string $content

add_filter( 'wpseo_video_index_content', 'fix_content_input', 10, 2 );

function fix_content_input( $content, $vid ) {
  $custom_field_name = 'video'; //Change to your needs
  $youtube_id = get_post_meta( $vid['post_id'], $custom_field_name, true );
  $content = "\n" . 'http://youtube.com/v/'. $youtube_id . "\n" . $content;
  return $content;

Haven’t added the custom field to our plugin-settings yet? Check our install guide.

Related articles

Get free SEO tips!