# Ability to place custom fields in post header?

**URL:** https://meta.discourse.org/t/ability-to-place-custom-fields-in-post-header/106928
**Category:** Support
**Created:** [January 18, 2019, 4:43pm UTC](https://meta.discourse.org/t/ability-to-place-custom-fields-in-post-header/106928 "2019-01-18T16:43:16Z")
**Posts on this page:** 1
**Showing post:** 2

<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: [January 19, 2019, 3:26am UTC](https://meta.discourse.org/t/ability-to-place-custom-fields-in-post-header/106928/2 "2019-01-19T03:26:57Z")

</div>

You can do a lot with the methods found in `plugin-api.js.es6`. To add content before or after the poster name widget, use the [decorateWidget method](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/plugin-api.js.es6#L281). Use `'poster-name:after'` as the name/type parameter.

Checking the result of the `console.log` statement from the following code will tell you what attributes are available:

```plaintext
<script type="text/discourse-plugin" version="0.8.27">
    api.decorateWidget('poster-name:after', helper => {
        console.log('attrs', helper.attrs);
    });
</script>

```

What you’ll see is that custom user fields are not available. To get access to them, you need to add the name of the user custom field to the `public user custom fields` Site Setting. Finding the name of the field can be tricky. One way to find the name is to go to `/admin/customize/user_fields.json` and look at the JSON for the page. You’ll see something like this:

```JSON
{
"user_fields": [
{
"id": 1,
"name": "Terms of Service",
"description": "<a href=\"http://localhost:3000/tos\">I have read the tos</a>",
"field_type": "confirm",
"editable": true,
"required": false,
"show_on_profile": false,
"show_on_user_card": false,
"position": 1
},
{
"id": 4,
"name": "city",
"description": "your city",
"field_type": "text",
"editable": true,
"required": true,
"show_on_profile": false,
"show_on_user_card": false,
"position": 3
}
]
}

```

You can get the name of the field by appending “user\_field\_” to the field’s ID. So the “city” field on my site has the name “user\_field\_4”. Add the name to the `public user custom fields` Site Setting so that it is available in `helper.attrs`.

 ![37%20PM](https://global.discourse-cdn.com/meta/original/3X/d/b/db6ee6d90300abf85e20fe249efb1ac38866a592.png)

The following code will add the city field after the `poster-name` widget for users who have set that custom field. The field is wrapped in `<span class="poster-user-field"></span>` tags, so it can be styled with CSS.

```plaintext
<script type="text/discourse-plugin" version="0.8.27">
    api.decorateWidget('poster-name:after', helper => {
        const attrs = helper.attrs;
        if (attrs.userCustomFields && attrs.userCustomFields.user_field_4) {
            return helper.h('span.poster-user-field', helper.attrs.userCustomFields.user_field_4);
        }
    });
</script>

```

 ![44%20PM](https://global.discourse-cdn.com/meta/original/3X/8/2/82d5b92d76177fd45fe0f1145c7bdd09097c122d.png)

---

_[View the full topic](https://meta.discourse.org/t/ability-to-place-custom-fields-in-post-header/106928)._
