View Categories

How to Make the Dynamic Text Translatable with Polylang

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 and wp_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:

  1. Log into your WordPress Dashboard.
  2. Navigate to: Languages → Translations.
  3. Search by group: Refer a Friend.
  4. You will find all the texts:
    • Share Text
    • Rewards Box
    • You Receive Label
    • You Receive Reward
    • Friend Receives Label
    • Friend Receives Reward
  5. Enter your translations for each language.
  6. Save Changes.

Done! Now both the Share Text and the Reward Box Texts will dynamically appear in the correct language.

What they say

Trusted by 7000+ customers

Our plugins are used by more than 7000 websites across the globe. All of our plugins are rated 5 stars on WordPress.org. Don’t just take our word for it, check what others are saying about WPGens.

I bought and tested the plugin with WooCommerce Subscription and it works like a charm. I had some specific questions to the developer and he responded very fast and helped me. I suggest the plugin!

Refer a Friend PREMIUM
@rinpocse91

If your looking to set up a referral program on your WooCommerce site to boost up your site sale “Refer A Friend for WooCommerce by WPGens” is your plugin to go for. Little blown away with an amazing support provided from (Goran) the plugin working exactly what you want to set up a referral system. Good job guys!

Refer a Friend PREMIUM
@samroon007

We deal with dozens of applications and plugins on a daily basis. Many of them are excellent, but few have truly excellent support. The Refer A Friend plugin is one of them: the response to my questions is always fast, friendly and very helpful.

Refer a Friend PREMIUM
@smartDIYer

This plugin is awesome. It looks good, it’s light weight, has great support – everything you can expect from a paid plugin, only it’s free!!!!

Swifty Bar
@ofirbeigel

Read all testimonials on WordPress Repository.

Get notified when we add new plugins.

We do not publish plugins often, but when we do, it's something awesome. No spam, we promise.

bool(false)