# Include the featured image in the post

**URL:** https://meta.discourse.org/t/include-the-featured-image-in-the-post/58196
**Category:** WordPress
**Created:** [March 1, 2017, 8:42pm UTC](https://meta.discourse.org/t/include-the-featured-image-in-the-post/58196 "2017-03-01T20:42:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Del33t](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Del33t](https://meta.discourse.org/u/Del33t)
#### Post date: [March 1, 2017, 8:42pm UTC](https://meta.discourse.org/t/include-the-featured-image-in-the-post/58196/1 "2017-03-01T20:42:57Z")

</div>

I’m trying to include the featured image of my wordpress post to be displayed in the Discourse linked topic. Ideally it would show above all the other post content (regardless on whether or not “show full post”/truncation is turned on or not). Any suggestions would be greatly appreciated!

Thank you

---

<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: [March 1, 2017, 9:19pm UTC](https://meta.discourse.org/t/include-the-featured-image-in-the-post/58196/2 "2017-03-01T21:19:14Z")

</div>

There’s an example of how to do that here: [Customize the structure of WP Discourse templates](https://meta.discourse.org/t/wp-discourse-template-customization/50754)

The example is under the heading **‘An example that adds the featured\_image to the publish template.’**

---

<div class="post-metadata">

### Author: ![Del33t](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Del33t](https://meta.discourse.org/u/Del33t)
#### Post date: [March 2, 2017, 8:11pm UTC](https://meta.discourse.org/t/include-the-featured-image-in-the-post/58196/3 "2017-03-02T20:11:31Z")

</div>

Awesome. Thank you simon. I did a search, but missed this example. I’ll see if I can’t get it working 🙂

---

<div class="post-metadata">

### Author: ![Del33t](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Del33t](https://meta.discourse.org/u/Del33t)
#### Post date: [March 2, 2017, 10:46pm UTC](https://meta.discourse.org/t/include-the-featured-image-in-the-post/58196/5 "2017-03-02T22:46:53Z")

</div>

Alright, I tried to get that to work but I was thrown a PHP error. (unexpected \< somewhere). I was able to add your other suggestion perfectly fine, [Clearing the text from the shortcode - #5 by Del33t](https://meta.discourse.org/t/clearing-the-text-from-the-shortcode/58036/5), but not when including the featured image. I imagine I’m copy+pasting too many things or the wrong things into my function.php file. I’m honestly confused with the majority of the following paragraph:

> This can be done in a custom template by copy and pasting the publish\_format\_html() function from it’s github, renaming the function by adding a namespace, adding the {featuredimage} template tag, removing the call to apply\_filters from the function’s return statement, and then hooking into the new function. Note: you also need to remove the self::get\_text\_options() statement from the original function.

And then additionally confused by the code you’ve added following it.

My function.php file is super simple at the moment:

```
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 15 );
function theme_enqueue_styles() {
    wp_enqueue_style( 'youplay-child', get_stylesheet_directory_uri() . '/style.css' );
}

add_filter( 'wp_discourse_excerpt', 'my_namespace_fix_shortcodes' );

function my_namespace_fix_shortcodes( $excerpt ) {
    $excerpt = str_replace( '[nk_title]', '<h2>', $excerpt );
    $excerpt = str_replace( '[/nk_title]', '</h2>', $excerpt ); 
    $excerpt = str_replace( '[yp_text]', '<p>', $excerpt );
    $excerpt = str_replace( '[/yp_text]', '</p>', $excerpt );

    $excerpt = preg_replace('(\\[([^[]|)*])', '', $excerpt );

    return $excerpt;
}

```

Sorry for my confusion, but do you have an guidance on this?

---

<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: [March 3, 2017, 5:35am UTC](https://meta.discourse.org/t/include-the-featured-image-in-the-post/58196/6 "2017-03-03T05:35:24Z")

</div>

I’m not sure, but it looks like there is a problem with the regular expression in the `preg_replace` statement. Try:  
`$excerpt = preg_replace( '/\[.*\]/', '', $excerpt );`

The best way to work things like this out is to do your development in a local development environment and figure out how to log the output so you can see what’s going on. (You can still connect to a remote Discourse forum. Just publish your posts to a private category.)

Getting too involved with basic PHP programming is probably outside of the scope of this forum. If you’re really stuck, send me a message and I’ll see if I can help.
