# Replace search keywords (whole words)

In case you need to replace certain whole words that the user enters to others (like synonyms), then use this custom code.

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

```php
add_filter( 'asp_query_args', 'asp_replace_search_keywords', 10, 2 );
function asp_replace_search_keywords( $args, $id ) {
  /**
   * Add as many words as you want. On the left side place the
   * word or words separated by comma to replace.
   * To the right side, place the single word to replace it with.
   */
  $replace = array(
    'word1' => 'word2',       // Replace 'word1' with 'word2'
    'word3, word4' => 'word5' // Replace 'word3' and 'word4' with 'word5'
  );

  // ----------------------------------------
  // Do not change anything below this line
  // ----------------------------------------
  foreach ( $replace as $k => $w ) {
    $kr = explode(',', $k);
    foreach ($kr as $krk => &$krv) {
      $krv = trim($krv);
      if ( $krv == '' ) {
        unset($kr[$krk]);
      } else {
        $krv = '/\b' . $krv . '\b/u';
      }
    }
    if ( count($krv) > 0 ) {
      $args['s'] = preg_replace($kr, $w, $args['s']);
    }
  }
  return $args;
}
```

Follow the instructions within the code to add/remove lines to the **$replace** array variable. Each key is a keyword or keywords separated by comma, and each value is the substitue keyword.


---

# 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/other/replace-search-keywords-whole-words.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.
