# Discourse\_publish\_format\_html -\> rewrite topic title?

**URL:** https://meta.discourse.org/t/discourse-publish-format-html-rewrite-topic-title/157659
**Category:** WordPress
**Created:** [July 14, 2020, 12:46am UTC](https://meta.discourse.org/t/discourse-publish-format-html-rewrite-topic-title/157659 "2020-07-14T00:46:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 14, 2020, 12:46am UTC](https://meta.discourse.org/t/discourse-publish-format-html-rewrite-topic-title/157659/1 "2020-07-14T00:46:04Z")

</div>

I’ve searched around and am not seeing anything specific about this. I can successfully grab and display custom fields when posting to Discourse from Wordpress as part of the topic “content” and create different templates according to post type, but is it possible to use a custom field to rewrite the Discourse topic title? Such as appending a formatted date field to an “event” title when it gets posted to Discourse?

---

<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: [July 14, 2020, 2:57am UTC](https://meta.discourse.org/t/discourse-publish-format-html-rewrite-topic-title/157659/2 "2020-07-14T02:57:59Z")

</div>

> [@Kayla](#):
>
> is it possible to use a custom field to rewrite the Discourse topic title?

Try hooking into the `wpdc_publish_format_title` filter. It’s passed two arguments: `$title` and `$post_id`.

Something like this should work:

```php
add_filter( 'wpdc_publish_format_title', 'wpdc_custom_publish_format_title', 10, 2 );
function wpdc_custom_publish_format_title( $title, $post_id ) {
    if ( get_post_meta( $post_id, 'your_meta_key', true ) ) {
        // Modify $title here.
    }

    return $title;
}

```

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 14, 2020, 8:07pm UTC](https://meta.discourse.org/t/discourse-publish-format-html-rewrite-topic-title/157659/3 "2020-07-14T20:07:49Z")

</div>

I will try this out as soon as I can, thank you for the pointer!

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 15, 2020, 8:25pm UTC](https://meta.discourse.org/t/discourse-publish-format-html-rewrite-topic-title/157659/4 "2020-07-15T20:25:05Z")

</div>

Works great! This has the same field data save timing issues as displaying custom fields in the content when [auto-publishing is enabled](https://meta.discourse.org/t/debugging-issue-with-custom-post-type-publishing-as-blank/157750/5) but the titles update as expected with this lag in mind. Thanks!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 14, 2020, 8:25pm UTC](https://meta.discourse.org/t/discourse-publish-format-html-rewrite-topic-title/157659/5 "2020-08-14T20:25:14Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
