Another solution is to use the specific hook ‘instant_articles_subtitle’:
This code is to set the subtitle from the excerpt:
add_filter('instant_articles_subtitle', 'my_subtitle', 10, 2);
function my_subtitle($subtitle, $instant_articles_post) {
$my_post = get_post($instant_articles_post->get_the_id());
$my_subtitle = $my_post->post_excerpt;
return $my_subtitle;
}
This is to set it from the first occurrence of the h2 tag in the post content:
add_filter('instant_articles_subtitle', 'my_subtitle', 10, 2);
function my_subtitle($subtitle, $instant_articles_post) {
$my_post = get_post($instant_articles_post->get_the_id());
preg_match('#<h2[^>]*>(.*?)</h2>#i', $my_post->post_content, $match);
$my_subtitle = $match[1];
return $my_subtitle;
}