For developers
Not a programmer? Feel free to skip this document. You don’t need to touch any code to use LingoPress: everything is done from the WordPress dashboard and is explained in the other guides (start with Getting started). This page is a technical reference, meant for anyone who wants to connect LingoPress with their own code: its functions, its “hooks” (points where you can plug in your own code) and its API.
Conventions: public functions with the lgp_ prefix, hooks with the lingopress_ prefix, namespace BallesDev\LingoPress, text domain lingopress. No Composer or external dependencies.
Public API (PHP)
Languages
| Function | What it does |
|---|---|
lgp_languages_list( $args ) |
List of the site’s languages. |
lgp_default_language( $field ) |
Default language (slug or another field). |
lgp_current_language( $field ) |
Language of the current request (frontend). |
lgp_add_language( $args ) |
Creates a language (regenerates rewrite rules automatically). |
Content
| Function | What it does |
|---|---|
lgp_set_post_language( $post_id, $lang ) |
Assigns a language to a post. |
lgp_get_post_language( $post_id, $field ) |
Language of a post. |
lgp_save_post_translations( $translations ) |
Links posts as translations ([ 'es' => 12, 'en' => 34 ]). |
lgp_get_post_translations( $post_id ) |
Translation group of a post. |
lgp_get_post( $post_id, $lang ) |
ID of a post’s translation in a given language. |
lgp_set_term_language / lgp_get_term_language |
Same for terms. |
lgp_save_term_translations / lgp_get_term_translations / lgp_get_term |
Same for terms. |
Presentation and strings
| Function | What it does |
|---|---|
lgp_the_languages( $args ) |
Renders the language switcher (see navigation). |
lgp_register_string( $name, $text ) |
Registers a translatable string in String translations. |
lgp__( $text ) / lgp_e( $text ) |
Returns / prints the translation of a registered string in the current language. |
lgp_translate_string( $text, $lang ) |
Translation of a string into a specific language. |
Hooks
| Hook | Type | When |
|---|---|---|
lingopress_language_defined |
action | The request’s language has been resolved (frontend, on setup_theme). |
lingopress_ai_system_prompt |
filter | Lets you modify the system prompt sent to the AI. |
lingopress_ai_provider |
filter | Lets you replace the AI provider (inject your own). |
lingopress_switcher_items |
filter | Modifies the items of the language switcher. |
lingopress_sync_post_meta |
filter | Adds your own metadata to the sync between translations. |
REST API
lang(read/write, with a capability check) andtranslationsfields in thewp/v2/*collections of the translatable post types and taxonomies.- Filtering collections by language with
?lang=:GET /wp-json/wp/v2/posts?lang=en.lang=alldisables the filter. - Custom endpoints:
GET /wp-json/lingopress/v1/languages(public);POSTandDELETErequiremanage_options. - The block editor preloads its collections already filtered by the language of the post being edited.
API keys via constants
In production, define the keys in wp-config.php — they take priority over the value stored in settings:
define( 'LINGOPRESS_ANTHROPIC_API_KEY', '...' );
define( 'LINGOPRESS_GEMINI_API_KEY', '...' );
define( 'LINGOPRESS_OPENAI_API_KEY', '...' );
define( 'LINGOPRESS_GROQ_API_KEY', '...' );
Data model
Four custom taxonomies, no custom tables: lgp_language and lgp_term_language (language of posts and terms), lgp_post_translations and lgp_term_translations (translation groups). The same model proven by Polylang, with its own prefix — it survives WXR exports/imports and can coexist with Polylang during a migration.
