# WP-discourse: how to deal with shortcodes in post

**URL:** https://meta.discourse.org/t/wp-discourse-how-to-deal-with-shortcodes-in-post/58838
**Category:** WordPress
**Created:** [10 Marzo 2017, 5:15pm UTC](https://meta.discourse.org/t/wp-discourse-how-to-deal-with-shortcodes-in-post/58838 "2017-03-10T17:15:03Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [15 Aprile 2017, 2:47am UTC](https://meta.discourse.org/t/wp-discourse-how-to-deal-with-shortcodes-in-post/58838/4 "2017-04-15T02:47:38Z")

</div>

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.

```plaintext
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' );

```

---

_[View the full topic](https://meta.discourse.org/t/wp-discourse-how-to-deal-with-shortcodes-in-post/58838)._
