In this discussion on the WP-Discourse plugin, users explore solutions for handling WordPress shortcodes when publishing posts to Discourse. tophee notes that raw text is published, not rendered HTML, making shortcodes unusable. simon suggests reviewing the ‘Dealing with WordPress shortcodes’ section in the WP-Discourse tips topic, noting that do_shortcode typically doesn’t work without plugin modifications. tophee shares a workaround: exporting only the post URL and enabling oneboxing. simon proposes embedding posts in iframes, especially for custom post types, and provides sample code — noting that Discourse must whitelist the iframe domain. jrgong tries embedding all posts in iframes but finds the src empty, prompting simon to suggest using get_the_permalink($post_id) instead of the_permalink(). jrgong confirms success and asks how to include hidden post text for SEO and searchability. simon advises wrapping the excerpt in a <div data-hide="true"> and hiding it via CSS in Discourse’s theme. jrgong clarifies whether {excerpt} includes the full post; simon confirms that selecting ‘display full post’ in WP-Discourse settings replaces {excerpt} with the full content. The thread offers practical, code-based workarounds for shortcode compatibility and SEO considerations.
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?
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.
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:
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' );
I used your template to customize the discourse_publish_format_html to display all posts in an iframe. However, the src parameter of the iframe output is empty. See here:
// show post in iframe
function your_namespace_publish_format_html( $output ) {
global $post;
?>
<iframe width="690" height="2000" src="<?php echo esc_url( the_permalink() ); ?>" frameborder="0"></iframe>
<?php
$output = ob_get_clean();
// Return the default output, or do something else with it here.
return $output;
}
add_filter( 'discourse_publish_format_html', 'your_namespace_publish_format_html' );
You can hide the post’s text with CSS by targeting a data attribute in your Discourse site’s theme. On WordPress, wrap the post excerpt in a div with a data attribute set to something like data-hide="true":
Doesn’t this template just add the excerpt instead? Or does the WP Discourse “display full post” setting display the full post for {excerpt} placeholder?