How to add Instagram Feed in wordpress single post

If you want to show instagram feed dynamically then use this code with this hook. So, when author add any Instagram link into the post editor section then it grabs the first link and convert it into instgram feed.

add_filter( ‘the_content’, ‘filter_the_content_in_the_main_loop’, 1 );

function filter_the_content_in_the_main_loop( $content ) {

if ((strpos($content, ‘https://www.instagram.com/’) !== false || strpos($content, ‘http://www.instagram.com/’) !== false) && (strpos($content, ‘?utm_source=’) || strpos($content, ‘?taken-by’) || strpos($content, ‘?utm_medium’) ) ) {

preg_match_all(‘#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#’, $content, $match);
foreach($match[0] as $mat) {
if(strpos($mat, ‘?’) !== false) {
if(isset($content1)) {
$content1 = str_replace( $mat, ‘<blockquote class=”instagram-media” data-instgrm-permalink=”‘ . $mat .'”></blockquote>’, $content1 );
}
else {
$content1 = str_replace( $mat, ‘<blockquote class=”instagram-media” data-instgrm-permalink=”‘ . $mat .'”></blockquote>’, $content );
}
}
}
$content1 .= ‘<script src=”//www.instagram.com/embed.js”></script>’;
return $content1;
}

return $content;
}