By default, adding the embed code or a link to a YouTube video in a comment form, won’t display your video because the oEmbed discovery for video tags is disabled.
To enable oEmbed discovery for video tags in WordPress comments, you need to add PHP code to your child themes functions file.
add_filter( 'comment_text', 'enable_video_in_comments', 0 );
function enable_video_in_comments( $comment ) {
add_filter( 'embed_oembed_discover', '__return_false', 999 );
$comment = $GLOBALS['wp_embed']->autoembed( $comment );
remove_filter( 'embed_oembed_discover', '__return_false', 999 );
return $comment;
}
Uses embed_oembed_discover
wrapped in the comment_text
filter.
The Jetpack plugin by Automattic includes shortcodes to do this however you need to add them every time you want to embed a video in a comment.
Once you add this code in your child themes functions.php file, you can simply drop a link to your video in the comments and WordPress will parse the video tags to display your video.
Was This Tutorial Helpful?