Sunday, January 23rd, 2022

Show Video in WordPress Post Comments

By default, adding an embed code or a link to a YouTube video in the comment form will not display your video because oEmbed search for the video tag is disabled.

To enable oEmbed search for video tags in WordPress comments, you need to add PHP code to your child theme 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;
}

Use embed_oembed_discover wrapped in comment_text Filtrate.

The Jetpack plugin by Automattic includes shortcodes to do this, although you need to add them each time you want to embed a video in a comment.

Once you have added this code to your child theme task.php file, you can just leave a link to your video in the comments and WordPress will parse the video tag to display your video.

Source link