> 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/wordpress/algolia-integration.md).

# Algolia integration

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 %}
