Show Videos in WordPress Post Comments

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.


Comments

2 responses to “Show Videos in WordPress Post Comments”

  1. Doesn’t work!
    useless!

    1. Might need updating which will only be done for paid members.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.