How to link a featured image back to its Wordpress post

Send your featured image from Wordpress to Discourse so that clicking on the image in Discourse takes you back to the wordpress post. Here’s what works for me. Hope it helps:

add_filter( 'discourse_publish_format_html', 'my_custom_publish_format', 10, 2  );

function my_custom_publish_format( $output, $post_id ) {
  $post = get_post( $post_id );
  $title = get_the_title($post->ID);
  $url = get_permalink($post->ID);
  if ( has_post_thumbnail( $post_id ) ) {
	$image = ' [![' . $title . '](' . get_the_post_thumbnail_url( $post->ID, 'medium' ) . ')](' . $url . ')' ;
  } else {
	$image = "";
  } ?>

       <?php ob_start(); ?>
	<small>Originally published at: {blogurl}</small><br>
        <?php echo $title ?><br>
        <?php echo $image ?>
        <?php $output = ob_get_clean();
        return $output;
    } ?>
2 Likes