If you’re using Polylang on your site, you can make both the Share Text and Reward Box Texts from Refer a Friend fully translatable.
Follow this step-by-step guide to enable translations for these options.
Step 1: Register the Dynamic Texts for Translation #
You need to tell Polylang which fields should be translatable.
Add the following code to your theme’s functions.php
file or inside your custom plugin:
phpCopyEditadd_action( 'init', function() {
if ( function_exists( 'pll_register_string' ) ) {
// Share Text
pll_register_string( 'Refer a Friend Share Text', get_option( 'gens_raf_share_text' ), 'Refer a Friend' );
// Rewards Box Texts
pll_register_string( 'Refer a Friend - Rewards Box', get_option( 'gens_raf_rewards_box' ), 'Refer a Friend' );
pll_register_string( 'Refer a Friend - You Receive Label', get_option( 'gens_raf_you_receive' ), 'Refer a Friend' );
pll_register_string( 'Refer a Friend - You Receive Reward', get_option( 'gens_raf_you_receive_reward' ), 'Refer a Friend' );
pll_register_string( 'Refer a Friend - Friend Receives Label', get_option( 'gens_raf_friend_receive' ), 'Refer a Friend' );
pll_register_string( 'Refer a Friend - Friend Receives Reward', get_option( 'gens_raf_friend_receive_reward' ), 'Refer a Friend' );
}
});
Explanation:
- Each option value is registered separately.
- They are grouped under “Refer a Friend” inside Polylang.
Step 2: Adjust Your Templates to Use Translations #
First copy template files to your theme per: https://wpgens.com/docs/how-to-edit-template-files-and-keep-them-after-plugin-update/
2.1. Update the Share Text Template #
Under modern/parts/text.php update code to this one:
<?php
$share_text = get_option( 'gens_raf_share_text' );
$share_text = function_exists( 'pll__' ) ? pll__( $share_text ) : $share_text;
?>
<div class="gens-raf-text">
<?php echo wp_kses_post( $share_text ); ?>
</div>
Notes:
pll__()
fetches the translated text.wp_kses_post()
safely allows basic HTML tags like<a>
,<strong>
, etc.
2.2. Update the Reward Box Template #
Under modern/parts/rewards.php update code to this:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$rewards_box = get_option( 'gens_raf_rewards_box' );
$you_receive = get_option( 'gens_raf_you_receive' );
$you_reward = get_option( 'gens_raf_you_receive_reward' );
$friend_receive = get_option( 'gens_raf_friend_receive' );
$friend_reward = get_option( 'gens_raf_friend_receive_reward' );
if ( function_exists( 'pll__' ) ) {
$rewards_box = pll__( $rewards_box );
$you_receive = pll__( $you_receive );
$you_reward = pll__( $you_reward );
$friend_receive = pll__( $friend_receive );
$friend_reward = pll__( $friend_reward );
}
if ( ! $rewards_box ) {
return;
}
?>
<div class="gens-raf-reward">
<div><?php echo wp_kses_post( $you_receive ); ?><span><?php echo wp_kses_post( $you_reward ); ?></span></div>
<span></span>
<div><?php echo wp_kses_post( $friend_receive ); ?><span><?php echo wp_kses_post( $friend_reward ); ?></span></div>
</div>
Notes:
- Again, we use
pll__()
for translation andwp_kses_post()
for safe output. - If the Reward Box content is empty, nothing will be displayed.
Step 3: Translate the Texts in Polylang #
Once the code is added:
- Log into your WordPress Dashboard.
- Navigate to: Languages → Translations.
- Search by group: Refer a Friend.
- You will find all the texts:
- Share Text
- Rewards Box
- You Receive Label
- You Receive Reward
- Friend Receives Label
- Friend Receives Reward
- Enter your translations for each language.
- Save Changes.
Done! Now both the Share Text and the Reward Box Texts will dynamically appear in the correct language.