1

In my posts, you can embed a video of Youtube by adding the link to the post. You don't have to do anything beside that.

On my comments, I can't do the same thing. Is it possible to embed Youtube video's by putting the link only (or a different manner, but I prefer the first), and if so, how?

3 Answers 3

4

Just add the comments to oEmbed. Here's a small plugin that you can use as MU-Plugin or normal plugin and that should explain what's going on pretty well.

<?php
defined( 'ABSPATH' ) or exit;
/* Plugin Name: (#105942) oEmbed Comments */

add_filter( 'comment_text', 'wpse_105942_oembed_comments', 0 );
function wpse_105942_oembed_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;
}
1
  • i think $comment_text in your code should be $comment to work properly or your can return $comment_text instead of $comment. Commented Jul 10, 2013 at 15:25
0

You can use jetpack plugin for embedding Youtube video's link in comment.

Important Links:

Shortcode Embeds

Embedding youtube link

1
  • Answers should be more than links.
    – kaiser
    Commented Jul 10, 2013 at 14:08
-1

To have them embedded nicely in comments with width responsive try fitvid

http://wordpress.org/plugins/fitvids-for-wordpress/

Works like a charm with the code snippet from above:

<?php
defined( 'ABSPATH' ) or exit;
/* Plugin Name: (#105942) oEmbed Comments */

add_filter( 'comment_text', 'wpse_105942_oembed_comments', 0 );
function wpse_105942_oembed_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;
}
2
  • 1
    Low quality posts are those that just have an outgoing link. Please summon the most important (code) bits in here.
    – kaiser
    Commented Jan 15, 2014 at 14:45
  • i dont really understand what you mean. this is a link to a wordpress plugin, how should i post the code?
    – vozer
    Commented Jan 16, 2014 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.