---
title: "Shortcodes - Language Switcher and Conditionals - PerfLocale"
description: "PerfLocale shortcode reference — language switcher, language conditionals, and the language-information helpers ready for any theme."
canonical: "https://perflocale.com/docs/shortcodes/"
source: "https://perflocale.com/docs/shortcodes/"
format: "markdown"
---
# Shortcodes

## `[perflocale_switcher]`

Displays the language switcher. See [Language Switcher](https://perflocale.com/docs/language-switcher/) for full documentation.

## `[perflocale_language]`

Outputs information about the current language.

### Attributes

| Attribute | Values | Default | Description |
| --- | --- | --- | --- |
| format | slug, locale, name, native_name, display_name, flag | name | What to output |

### Format Values

| Format | Example Output | Description |
| --- | --- | --- |
| slug | fr | 2-3 letter language code |
| locale | fr_FR | Full WordPress locale |
| name | French | English language name |
| native_name | Français | Name in the language itself |
| display_name | French (Français) | English name with native in parentheses |
| flag | 🇫🇷 | Flag emoji |

### Examples

```
Current language: [perflocale_language]
→ "Current language: French"

Code: [perflocale_language format="slug"]
→ "Code: fr"

Locale: [perflocale_language format="locale"]
→ "Locale: fr_FR"

[perflocale_language format="native_name"]
→ "Français"

[perflocale_language format="display_name"]
→ "French (Français)"

[perflocale_language format="flag"]
→ "🇫🇷"
```

### Use Cases

-   Show current language in a header or footer
-   Display language info in widgets
-   Dynamic page titles: `Welcome - [perflocale_language format="native_name"]`

## `[perflocale_if]`

Shows or hides its enclosed content based on the visitor’s current language. Same behaviour is also available as a Gutenberg block and as a PHP helper - all three share a single core predicate so they can’t drift apart.

### Attributes

| Attribute | Values | Description |
| --- | --- | --- |
| langs | Comma-separated language slugs - e.g. fr,de | Show the enclosed content only in these languages. |
| not_langs | Comma-separated language slugs - e.g. en,fr | Inverse: show everywhere except these languages. Takes precedence over langs when both are set. |

### Examples

```
[perflocale_if langs="fr,de"]
	Shown only to French and German visitors.
[/perflocale_if]

[perflocale_if not_langs="en"]
	Shown to every visitor except those browsing the English version.
[/perflocale_if]

[perflocale_if langs="fr"]
	<a href="/fr/promo/">Voir la promo</a>
[/perflocale_if]
```

Nested shortcodes and blocks inside the enclosed content are resolved normally. When no visitor language is resolved the block hides (fail-closed) to avoid leaking content into the wrong locale during edge-case detection failures.

### Gutenberg block

Search “Show If Language” in the block inserter. The block exposes the same two options as the shortcode - a multi-select of active languages and an “Invert” toggle - and supports inner blocks of any kind.

### PHP helper

For theme templates, use the helper directly:

```php
<?php if ( perflocale_if_language( [ 'fr', 'de' ] ) ) : ?>
	<div class="banner">Offre spéciale locale</div>
<?php endif; ?>

// Invert: show everywhere EXCEPT these languages.
<?php if ( perflocale_if_language( [ 'en' ], true ) ) : ?>
	...
<?php endif; ?>

// Accepts a single slug, comma-separated string, or array:
perflocale_if_language( 'fr' );
perflocale_if_language( 'fr,de' );
perflocale_if_language( [ 'fr', 'de' ] );
```

### Notes

-   Language slugs are matched against the active languages configured under **Languages**.
-   Evaluation is a single `in_array()` plus a cached current-language lookup - zero database I/O per call.
-   If `langs` and `not_langs` are both set, `not_langs` wins (the shortcode treats that as an inversion request).
