This code snippet adds a new condition in Breakdance, allowing you to select any language you've previously added through TranslatePress.
While this code was AI-generated, it has been thoroughly tested and verified.
Copy and paste the code below into a Snippet Manager. For best results, we recommend using WPCodeBox, the top solution available.

<?php
/**
* Breakdance condition: show / hide content based on the
* current TranslatePress language.
*/
add_action( 'breakdance_register_template_types_and_conditions', function () {
// Make sure TranslatePress (free or PRO) is active.
if ( function_exists( 'trp_get_languages' ) ) {
/**
* TranslatePress returns an associative array where the key
* is the locale code (e.g. en_US, fr_FR) and the value is an array
* with flag, name, slug, etc.
* We only need the keys.
*/
$lang_list = array_keys( trp_get_languages() ); // e.g. ['en_US','fr_FR'].
\Breakdance\ConditionsAPI\register( [
'supports' => [ 'element_display', 'templating' ],
'slug' => 'translatepress4bd-condition', // MUST be unique.
'label' => 'Language',
'category' => 'TranslatePress',
'operands' => [ 'equals', 'not equals' ],
'values' => function () use ( $lang_list ) {
return [
[
'label' => 'Language',
'items' => array_map(
fn ( $lang ) => [ 'text' => $lang, 'value' => $lang ],
$lang_list
),
],
];
},
'allowMultiselect' => false,
'callback' => function ( string $operand, $value ) {
$current_lang = get_locale(); // TranslatePress filters this.
if ( 'equals' === $operand ) {
return $current_lang === $value;
}
if ( 'not equals' === $operand ) {
return $current_lang !== $value;
}
return false;
},
] );
}
} );
/**
* Breakdance condition: show / hide content based on the
* current TranslatePress language.
*/
add_action( 'breakdance_register_template_types_and_conditions', function () {
// Make sure TranslatePress (free or PRO) is active.
if ( function_exists( 'trp_get_languages' ) ) {
/**
* TranslatePress returns an associative array where the key
* is the locale code (e.g. en_US, fr_FR) and the value is an array
* with flag, name, slug, etc.
* We only need the keys.
*/
$lang_list = array_keys( trp_get_languages() ); // e.g. ['en_US','fr_FR'].
\Breakdance\ConditionsAPI\register( [
'supports' => [ 'element_display', 'templating' ],
'slug' => 'translatepress4bd-condition', // MUST be unique.
'label' => 'Language',
'category' => 'TranslatePress',
'operands' => [ 'equals', 'not equals' ],
'values' => function () use ( $lang_list ) {
return [
[
'label' => 'Language',
'items' => array_map(
fn ( $lang ) => [ 'text' => $lang, 'value' => $lang ],
$lang_list
),
],
];
},
'allowMultiselect' => false,
'callback' => function ( string $operand, $value ) {
$current_lang = get_locale(); // TranslatePress filters this.
if ( 'equals' === $operand ) {
return $current_lang === $value;
}
if ( 'not equals' === $operand ) {
return $current_lang !== $value;
}
return false;
},
] );
}
} );