WP Discourse - Template Customization

Depending on how your videos have been published, you might be able to use something like this:

add_filter( 'discourse_publish_format_html', 'my_namespace_publish_format', 10, 2 );
function my_namespace_publish_format( $input, $post_id ) {
	$post_content = apply_filters( 'the_content', get_post( $post_id )->post_content );
	$videos = get_media_embedded_in_content( $post_content );
	$video_string = '';
	foreach( $videos as $video ) {
	    $video_string .= $video . '<br>';
    }
    ob_start();

    echo '<small>Originally published at {blogurl}</small><br><br>';
    echo $video_string;
    echo '{excerpt}';
    $output = ob_get_clean();

    return $output;
}

This should work if the videos are embedded on your WordPress site. It make take some trial and error to get the formatting correct. The main problem I ran into with it was that if there are leading spaces before the Youtube iframe tag, Discourse will interpret it as code.

Let me know if this approach doesn’t work on your site.

What I would like to get to work would be to have Youtube videos displayed when users click the “Show Full Post” button on Discourse to expand a WordPress post. I am not sure if that is going to be possible though.

1 « J'aime »