Support Log in

4. String Translation Functions

Developer Guide
Prefer video? Watch the Lang Forge tutorials 9 short guides covering every feature Watch

Functions for translating arbitrary strings (text that is not post content). Used for theme labels, button text, widget titles, page builder content, and any other hardcoded strings in templates.

Translating Strings

Lang Forge works with standard WordPress translation functions. Use __(), _e(), esc_html__(), and esc_html_e() with your theme’s text domain. When auto-registration is enabled for your text domain, Lang Forge automatically detects these strings and makes them available for translation in the admin panel.

Example 1: Basic usage in a template
php
<h1><?php echo esc_html__('Welcome to our store', 'theme'); ?></h1>
<p><?php echo esc_html__('Browse our collection of handmade goods', 'theme'); ?></p>
Example 2: Echo version
php
<button class="btn-submit">
    <?php _e('Submit Form', 'theme'); ?>
</button>

<footer>
    <p><?php _e('All rights reserved', 'theme'); ?></p>
</footer>
Example 3: Dynamic strings with sprintf
php
// Translate the template, then fill in dynamic values
$template = __('Showing %d results for "%s"', 'theme');
echo sprintf($template, $count, esc_html($search_term));
Example 4: Translate a button
php
<a href="<?php the_permalink(); ?>" class="btn btn-primary">
    <?php echo esc_html__('Read More', 'theme'); ?>
</a>
Example 5: Translate breadcrumb labels
php
function theme_breadcrumbs() {
    $home_label = __('Home', 'theme');
    $separator  = ' &raquo; ';

    echo '<nav class="breadcrumbs">';
    echo '<a href="' . esc_url(home_url('/')) . '">' . esc_html($home_label) . '</a>';

    if (is_category()) {
        echo $separator . esc_html(single_cat_title('', false));
    } elseif (is_single()) {
        $categories = get_the_category();
        if ($categories) {
            echo $separator . '<a href="' . esc_url(get_category_link($categories[0]->term_id)) . '">';
            echo esc_html($categories[0]->name) . '</a>';
        }
        echo $separator . esc_html(get_the_title());
    }
    echo '</nav>';
}

Forge AI Assistant Online

Hi! I'm the Lang Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs