# "Also Available In" Links Above Polylang Posts

> Shows a short line above each post or page listing the other languages it has been translated into, with links, so visitors who arrive in the wrong language can switch straight away.

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

## Code

```php
$wpide_label = 'Also available in:'; // Text before the links.

add_filter( 'the_content', function ( $content ) use ( $wpide_label ) {
    if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || ! function_exists( 'pll_get_post_translations' ) ) {
        return $content;
    }

    $current      = pll_current_language();
    $translations = pll_get_post_translations( get_the_ID() );
    $names        = array_combine( pll_languages_list( array( 'fields' => 'slug' ) ), pll_languages_list( array( 'fields' => 'name' ) ) );
    $links        = array();

    foreach ( $translations as $slug => $post_id ) {
        if ( $slug === $current || 'publish' !== get_post_status( $post_id ) ) {
            continue;
        }
        $links[] = sprintf( '<a href="%1$s" hreflang="%2$s" lang="%2$s">%3$s</a>', esc_url( get_permalink( $post_id ) ), esc_attr( $slug ), esc_html( isset( $names[ $slug ] ) ? $names[ $slug ] : strtoupper( $slug ) ) );
    }

    if ( ! $links ) {
        return $content;
    }

    $label = function_exists( 'pll__' ) ? pll__( $wpide_label ) : $wpide_label;

    return '<p class="wpide-pll-available">' . esc_html( $label ) . ' ' . implode( ', ', $links ) . '</p>' . $content;
} );
```

## Notes

Hidden when the post has no translations. Change $wpide_label, or register it as a Polylang string to translate it.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Also Available In" Links Above Polylang Posts" 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/
