For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

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

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:

This integration is still a Work In Progress. Your feedback is welcome to help us improve it.

Last updated