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.

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.

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.