# Displaying taxonomy name in taxonomy term results

This custom code is to display the taxonomy name along with the term results.<br>

![](https://1744076133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M9rmHbZfTKVQ7YzbIZL%2Fuploads%2Fv3LbWWzSANAbegyKkNrb%2Fimage.png?alt=media\&token=a32b9059-bf06-4350-868d-bbdaf490b721)

[What is this, and where do I put this custom code?](https://knowledgebase.ajaxsearchpro.com/safe-coding-guideline)

```php
add_filter('asp_results', 'asp_display_tax_name_in_results');
function asp_display_tax_name_in_results($results) {
	// Change these variables according to the comments after
	$position = 'before'; 	// 'before' or 'after'
	$field = 'title';		// 'title' or 'content'
	$delimiter = ' - '; 	// Characters between the taxonomy name and the field

	// --- DO NOT CHANGER ANYTHING BELOW ---
	foreach($results as $k=>&$r){
		if ( $r->content_type == 'term' ) {
			$taxonomy = get_taxonomy( $r->taxonomy );
			if ( !is_wp_error($taxonomy) ) {
				if ( $field == 'title' ) {
					$f = &$r->title;
				} else {
					$f = &$r->content;
				}
				if ( $position == 'before' ) {
					$f = $taxonomy->labels->name  . $delimiter . $f;
				} else {
					$f .= $delimiter . $taxonomy->labels->name;
				}
				}
			}
	}
	return $results;
}
```

#### Variable to change in the code

* **$position** (line 4) - 'before' or 'after', where you need to display the taxonomy name
* **$field** (line 5) - The field name, 'title' or 'content'
* **$delimiter** (line 6) - String, which is placed between the taxonomy name and the field
