Skip to content

How to remove captions from Instagram embeds in WordPress

This is a simple code snippet to achieve just that in Instagram embeds, via shortcode or using Gutenberg.

function custom_instagram_settings($code){
    if(strpos($code, 'instagr.am') !== false || strpos($code, 'instagram.com') !== false){ // if instagram embed
	    $return = preg_replace("@data-instgrm-captioned@", "", $code); // remove caption class
	    return $return;
    }
    return $code;
}

add_filter('embed_handler_html', 'custom_instagram_settings');
add_filter('embed_oembed_html', 'custom_instagram_settings');

[instagram url=https://www.instagram.com/p/B1WjYcxCmHp/ hidecaption=true]

You can achieve the same effect in single embeds by using the following shortcode

[[instagram url=https://www.instagram.com/p/B1WjYcxCmHp/ hidecaption=true]]

Here’s the result

[instagram url=https://www.instagram.com/p/B1WjYcxCmHp/ hidecaption=true]

YouTube

Use this snippet if you want to achieve a similar result wit YouTube embeds:

/* Youtube Videos remove show info related etc */
function custom_youtube_settings($code){
    if(strpos($code, 'youtu.be') !== false || strpos($code, 'youtube.com') !== false){
	    $return = preg_replace("@src=(['\"])?([^'\">\s]*)@", "src=$1$2&cc_lang_pref=en&hl=en&showinfo=0&rel=0&autohide=1&modestbranding=1&iv_load_policy=3", $code);
	    return $return;
    }
    return $code;
}

add_filter('embed_handler_html', 'custom_youtube_settings');
add_filter('embed_oembed_html', 'custom_youtube_settings');

Has this worked for you?

Found: on Reddit