> For the complete documentation index, see [llms.txt](https://knowledgebase.ajaxsearchpro.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledgebase.ajaxsearchpro.com/miscellaneous/tutorials/indexing-shortcodes-within-custom-field-contents.md).

# Indexing Shortcodes within custom field contents

By default shortcodes are not executed in custom field contents before indexing to avoid some known issues. In rare cases - such as using an ACF field with a Tablepress or any other shortcode it is neccessary.

### Steps to get a shortcode indexed in a custom field

* Configure the [index table engine](https://documentation.ajaxsearchpro.com/index-table) as you need it, but don't index yet (Don't click Create New index button, if you did, just reload the page)
* Make sure that the custom field, which contains the shortcode(s) is also selected. In this example I'm using "field\_name" as the field.<br>

  <figure><img src="/files/cltPkXzkWr6gGpGTm29k" alt="" width="188"><figcaption></figcaption></figure>
* Use the custom code below. [Where do I put the custom code?](/safe-coding-guideline.md)
* Make sure to change the **$field\_name** variable to the custom field, which contains the shortcode(s)
* Now create the index<br>

  <figure><img src="/files/COxXTkVMGfJS1RK5XTrB" alt="" width="188"><figcaption></figcaption></figure>
* Make sure that the index table engine [is enabled](https://documentation.ajaxsearchpro.com/index-table/enabling-index-table-engine) on the search instance settings as well

The custom code snippet to index custom field with shortcodes:

```php
add_filter(
	'asp_post_custom_field_before_tokenize',
	function ( $values, $the_post, $field ) {
		$field_name = 'field_name';

		// Do not change anything below
		$new_values = array();
		if ( $field === $field_name ) {
			foreach( $values as $value ) {
				$new_values[] = do_shortcode($value);
			}
		}

		return $new_values;
	},
	10,
	3
);
```
