WP-discourse: how to deal with shortcodes in post

For posts where you need the shortcode content to be published to Discourse, it’s possible to publish the post in an iframe. This works best if the WordPress posts uses a custom post-type. That way you can decide which posts are to be published in an iframe. It takes a bit of work on the WordPress end so that posts are published in a format that’s suitable for putting in an iframe. You also need to be able to whitelist the iframe on Discourse for this to work.

I’ve been testing this with both an image gallery shortcode, and a groups sign-up form. It seems to be working quite well.

function your_namespace_publish_format_html( $output ) {
    global $post;

    if ( 'my_iframe_post_type' === $post->post_type) {
	ob_start();

	?>
    <iframe width="690" height="600" src="<?php echo esc_url( the_permalink() ); ?>" frameborder="0"></iframe>
	<?php
	$output = ob_get_clean();

	// Return an iframe for this post type.
	return $output;
    }

    // Return the default output, or do something else with it here.
    return $output;
}
add_filter( 'discourse_publish_format_html', 'your_namespace_publish_format_html' );
4 Likes