WP-discourse: how to deal with shortcodes in post

(Christoph) #1

I noticed that what WP-discourse is publishing to Discourse are the raw texts from the WordPress posts, not the rendered html. And I guess that makes some sense, given how complex wordpress pages can be. But it’s also a problem since it means you can’t use any shortcodes (or you can’t use discourse with the posts where you do)…

Is there any workaround for this?

Are there any plans of maybe providing an option to use the rendered html as the basis for the discourse post?

(Simon Cossar) #2

Take a look at the ‘Dealing with WordPress shortcodes’ section of this topic: WP Discourse Plugin Tips and Tricks
The do_shortcode option that’s given in that topic generally doesn’t work, but I think some changes could be made to the plugin to get it working.

(Christoph) #3

I solved this by circumventing the content of the post and merely exporting the post url via the plugin while making sure that it will be oneboxed, like this:

(Simon Cossar) #4

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) {

    <iframe width="690" height="600" src="<?php echo esc_url( the_permalink() ); ?>" frameborder="0"></iframe>
	$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' );

WP Discourse: advanced custom filter for discourse_publish_format_html