# Polylang Translations Menu in the Toolbar

> Adds a "Translations" toolbar menu on posts and pages with links to edit each existing language version, plus links to create the missing ones.

- Type: PHP
- Runs: Run everywhere
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: polylang, admin-bar, translations
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/pll-admin-bar-translations/

## Code

```php
add_action( 'admin_bar_menu', function ( $bar ) {
    if ( is_admin() || ! is_singular() || ! function_exists( 'pll_get_post_translations' ) ) {
        return;
    }

    $id = get_queried_object_id();

    if ( ! current_user_can( 'edit_post', $id ) || ! pll_is_translated_post_type( get_post_type( $id ) ) ) {
        return;
    }

    $translations = pll_get_post_translations( $id );

    $bar->add_node( array( 'id' => 'wpide-pll-tr', 'title' => esc_html__( 'Translations' ) ) );

    foreach ( pll_languages_list( array( 'fields' => 'slug' ) ) as $slug ) {
        if ( ! empty( $translations[ $slug ] ) ) {
            $href  = get_edit_post_link( $translations[ $slug ], 'raw' );
            $label = strtoupper( $slug ) . ( (int) $translations[ $slug ] === $id ? ' (this page)' : '' );
        } else {
            $href  = add_query_arg( array( 'post_type' => get_post_type( $id ), 'from_post' => $id, 'new_lang' => $slug, '_wpnonce' => wp_create_nonce( 'new-post-translation' ) ), admin_url( 'post-new.php' ) );
            $label = '+ ' . strtoupper( $slug );
        }

        if ( $href ) {
            $bar->add_node( array( 'parent' => 'wpide-pll-tr', 'id' => 'wpide-pll-tr-' . sanitize_key( $slug ), 'title' => esc_html( $label ), 'href' => $href ) );
        }
    }
}, 90 );
```

## Notes

Visible only to users who can edit the post.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Polylang Translations Menu in the Toolbar" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
