# Translatable Announcement Bar With WPML

> Shows a slim announcement bar at the top of every page whose text you translate in WPML > String Translation, so each language gets its own message.

- Type: PHP
- Runs: Run everywhere
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: wpml, announcement, string-translation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpml-translatable-announcement/

## Code

```php
$wpide_text = 'Free shipping on orders over $50 this week only.'; // Default-language text.
$wpide_link = '/shop/';                                          // Optional link, or ''.

add_action( 'admin_init', function () use ( $wpide_text, $wpide_link ) {
    if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) {
        return;
    }
    do_action( 'wpml_register_single_string', 'WPIDE Snippets', 'Announcement text', $wpide_text );
    if ( $wpide_link ) {
        do_action( 'wpml_register_single_string', 'WPIDE Snippets', 'Announcement link', $wpide_link );
    }
} );

add_action( 'wp_body_open', function () use ( $wpide_text, $wpide_link ) {
    if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) {
        return;
    }

    $text = apply_filters( 'wpml_translate_single_string', $wpide_text, 'WPIDE Snippets', 'Announcement text' );
    $link = $wpide_link ? apply_filters( 'wpml_translate_single_string', $wpide_link, 'WPIDE Snippets', 'Announcement link' ) : '';

    if ( '' === trim( (string) $text ) ) {
        return;
    }

    if ( $link && 0 === strpos( $link, '/' ) ) {
        $link = apply_filters( 'wpml_permalink', home_url( $link ) );
    }

    echo '<div class="wpide-announcement" role="region" aria-label="' . esc_attr__( 'Announcement' ) . '" style="background:#1d2327;color:#fff;text-align:center;padding:8px 16px;font-size:14px">';
    echo $link ? '<a href="' . esc_url( $link ) . '" style="color:inherit">' . esc_html( $text ) . '</a>' : esc_html( $text );
    echo '</div>';
} );
```

## Notes

Edit $wpide_text and $wpide_link, visit the dashboard once, then translate the strings under the "WPIDE Snippets" domain in String Translation.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Translatable Announcement Bar With WPML" 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/
