0

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?

2

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;
}
  • i think $comment_text in your code should be $comment to work properly or your can return $comment_text instead of $comment. – Ravinder Kumar Jul 10 '13 at 15:25
0

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

Important Links:

Shortcode Embeds

Embedding youtube link

  • Answers should be more than links. – kaiser Jul 10 '13 at 14:08
0

This question needs a newer answer:

add_filter( 'comment_text', 'your_child_theme_prefix_oembed_comments', 0 );
/**
 * Use oEmbeds in comments
 */
function your_child_theme_prefix_oembed_comments( $comment ) {

    global $wp_embed;

    if ( ! is_admin() ) :
        $comment = $wp_embed->autoembed( $comment );
    endif;

    return $comment;
}
-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;
}
  • 1
    Low quality posts are those that just have an outgoing link. Please summon the most important (code) bits in here. – kaiser Jan 15 '14 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 Jan 16 '14 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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