Translatepress language ui navigation

From Lonsdale201/wp-agent-skills · View interactive version

Translatepress language ui navigation is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Build or audit TranslatePress language UI compatibility for WordPress themes/plugins. Use for custom language switchers, `[language-switcher]`, `trp_custom_language_switcher()`, `[language-include]`, `[language-exclude]`, legacy `[trp_language]`, per-language menus, Navigation Based on Language, con

How to use this skill

Skill file

TranslatePress Language UI And Navigation

Use TranslatePress APIs and add-ons for language switchers, menu visibility, translator access, and language-detection UI. Theme/plugin code should not infer languages from URL segments when TranslatePress already exposes current-language URLs and Business add-ons can use different domains.

When to use this skill

Trigger when ANY of the following is true:

Prefer built-in switchers first

Use built-in TranslatePress switchers when design requirements are ordinary:

Only build a custom switcher when the theme needs custom markup or a component-system integration.

Custom language switcher

Use trp_custom_language_switcher() when available:

if ( function_exists( 'trp_custom_language_switcher' ) ) {
    $languages = trp_custom_language_switcher();

    echo '<nav class="my-language-switcher" data-no-translation aria-label="' . esc_attr__( 'Language', 'mytheme' ) . '">';
    foreach ( $languages as $language ) {
        printf(
            '<a href="%s" hreflang="%s"><img src="%s" alt="" /> <span>%s</span></a>',
            esc_url( $language['current_page_url'] ),
            esc_attr( str_replace( '_', '-', $language['language_code'] ) ),
            esc_url( $language['flag_link'] ),
            esc_html( $language['language_name'] )
        );
    }
    echo '</nav>';
}

The docs require data-no-translation on the wrapper so TranslatePress does not translate the switcher links themselves. The returned array includes language name, language code, short language name/slug, flag URL, and current-page URL for that language.

Do not compute switcher URLs manually from URL slugs. That breaks default-language subdirectory settings, unpublished languages, translated slugs, and Different Domain per Language.

Conditional content

Prefer the current core conditional shortcodes:

[language-include lang="en_US,fr_FR" enable_translation="yes"]Visible in selected languages[/language-include]
[language-exclude lang="de_DE" enable_translation="no"]Hidden in German and not translated elsewhere[/language-exclude]

enable_translation="no" wraps the content in data-no-translation, so use it only when the included content must remain literal.

The older shortcode still exists but is deprecated in core 3.2.1:

[trp_language language="en_US"]English-only content[/trp_language]

Avoid adding new [trp_language] usage. Keep it only for legacy content until it can be migrated. Use conditional shortcodes for small editorial blocks only. For structural theme logic, prefer normal templates plus translated content. Do not hide checkout, account, legal, or accessibility-critical controls by language unless the business requirement is explicit.

Navigation Based on Language

The add-on stores allowed languages in menu item meta _trp_menu_languages and filters front-end menu items through wp_get_nav_menu_items. It also hides children of hidden parents and passes visibility through nav_menu_roles_item_visibility.

Theme rules:

Plugin rules:

$items = wp_get_nav_menu_items( $menu_id ); // lets TranslatePress hide language-limited items.

Do not read _trp_menu_languages and implement a parallel visibility system unless you must support a non-WP menu renderer.

Translator Accounts

Translator Accounts creates/updates a translator role with:

It also:

If your plugin/theme hides the admin bar or blocks wp-admin for non-admin roles, allow current_user_can( 'translate_strings' ) where the feature is only about translation access. Do not give translators plugin settings capabilities unless they need them.

Browse as User Role

Browse as User Role adds all roles to the translation editor "View as" selector, adds nonces per role, and temporarily changes the current user role during preview with trp_temporary_change_current_user_role.

Compatibility rules:

Automatic User Language Detection UI

Automatic User Language Detection:

Theme/plugin checks:

Test matrix

Run UI checks across:

Critical rules

Cross-references

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.