# How to add shortcode to the results content?

[What is this, and where do I put this custom code?](/safe-coding-guideline.md)

```php
add_filter( 'asp_results', 'asp_my_custom_shortcodes_in_results', 10, 4 );
function asp_custom_link_results( $results, $search_id, $is_ajax, $args ) {
    foreach ($results as $k=>&$r) {
		if ( isset($r->post_type) ) {
			$r->content .= do_shortcode("[my_custom_shortcode]");
		}
    }
    return $results;
}
```

It is also possible to pass the post ID to the shortcode as a parameter if neccessary:

```php
add_filter( 'asp_results', 'asp_my_custom_shortcodes_in_results', 10, 4 );
function asp_custom_link_results( $results, $search_id, $is_ajax, $args ) {
    foreach ($results as $k=>&$r) {
		if ( isset($r->post_type) ) {
			$r->content .= do_shortcode("[my_custom_shortcode id={$r->id}]");
		}
    }
    return $results;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/miscellaneous/tutorials/how-to-add-shortcode-to-the-results-content.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
