> For the complete documentation index, see [llms.txt](https://developers.weglot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.weglot.com/cms/wordpress/algolia-integration.md).

# Algolia integration

Integration between Algolia and the Weglot WordPress plugin.

Algolia is a powerful search and discovery API platform designed to create fast and relevant search experiences for websites and applications. It provides tools to index, search, and analyze data in real-time, ensuring that users can quickly find what they're looking for.

To install Algolia, please follow the steps described in this link: [Algolia WordPress Integration Setup](https://www.algolia.com/doc/integration/wordpress/indexing/setting-up-algolia/?client=php).

To make Algolia work with Weglot, add the following code to a snippet or directly into your own code:

```php
function algolia_load_assets() {
    wp_enqueue_script( 'xhook', 'https://unpkg.com/xhook@1.6.2/dist/xhook.min.js', array(), '1.6.2', true );

    $algolia_url  = WEGLOT_DIRURL . 'app/javascripts/algolia.js';
    $algolia_file = WEGLOT_DIR . '/app/javascripts/algolia.js';
    $algolia_ver  = file_exists( $algolia_file ) ? filemtime( $algolia_file ) : WEGLOT_VERSION;

    wp_enqueue_script( 'wg-algolia-js', $algolia_url, array( 'xhook' ), $algolia_ver, true );

    wp_localize_script( 'wg-algolia-js', 'weglotData', array(
        'api_key'           => weglot_get_option( 'api_key' ),
        'original_language' => weglot_get_original_language(),
        'current_language'  => weglot_get_current_language(),
    ) );
}
add_action( 'wp_enqueue_scripts', 'algolia_load_assets' );
```

This loads the Algolia JavaScript file shipped with Weglot together with the xhook library (used to intercept and proxy Algolia requests), and passes your Weglot configuration (API key, original and current language) to the script. If everything is set up correctly, you should see both scripts loaded on your page.

To complete the setup, add the following definitions to your Weglot custom settings to specify what content to translate:

```json
"definitions": {
  "translations": [
    {
      "type": "JSON",
      "value": [
        {
          "paths": [
            "$.results[*].hits[*].post_title",
            "$.results[*].hits[*].content",
            "$.results[*].hits[*]._snippetResult.post_title.value",
            "$.results[*].hits[*]._snippetResult.content.value",
            "$.hits[*].post_title",
            "$.hits[*].content",
            "$.hits[*]._snippetResult.post_title.value",
            "$.hits[*]._snippetResult.content.value"
          ]
        }
      ]
    }
  ]
}
```

<figure><img src="https://2434047128-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LBR06TZOLDcORpsmGB4%2Fuploads%2F7NUW7nArtWWfoxNrfq1o%2Fimage.png?alt=media&#x26;token=9707595d-570e-4f44-9563-1a35cc77e8da" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
This integration is still a Work In Progress. Your feedback is welcome to help us improve it.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.weglot.com/cms/wordpress/algolia-integration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
