Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

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;
}
share|improve this answer
    
i think $comment_text in your code should be $comment to work properly or your can return $comment_text instead of $comment. –  Ravs Jul 10 '13 at 15:25
    
@Ravs Fixed, thanks. –  kaiser Jul 10 '13 at 15:33
1  
Worked like a charm. Thanks man! –  Johan Jul 20 '13 at 8:45

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

Important Links:

Shortcode Embeds

Embedding youtube link

share|improve this answer
    
Answers should be more than links. –  kaiser Jul 10 '13 at 14:08

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;
}
share|improve this answer
1  
Low quality posts are those that just have an outgoing link. Please summon the most important (code) bits in here. –  kaiser Jan 15 at 14:45
1  
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  t f Jan 15 at 14:49
    
i dont really understand what you mean. this is a link to a wordpress plugin, how should i post the code? –  user1853564 Jan 16 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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