• Hello!

    I want to echo custom string translation into template page.

    e.g

    echo ‘<div class=”related”><h4 class=”related-portfolio”> pll_e(‘varietes’) </h4>

      ‘;

      what is the right syntax to make it work?

      Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi
    I have used the following:

    <?php $allrightsreserved = pll__('All Rights Reserved'); ?>

    and then inserted the variable into the copyright bit at the bottom of the page.

    <?php echo '&copy;&nbsp;' . date('Y') . ', ' . $allrightsreserved; ?>

    I hope that helps.

    Morris

    Thread Starter oribrn

    (@oribrn)

    the template syntax is:

    echo '<div class="related"><h4 class="related-portfolio"> text label </h4><ul>';

    I want to replace “text label” with new string translation.

    I have also register a string in functions.php:

    (add_action('init', function() {  pll_register_string('mytheme-hello', 'varietes');
    });)

    I am trying pll_e(‘varietes’) but the syntax does not work

    Hi
    pll_e
    Echoes a translated string previously registered with pll_register_string, I have just tried this on my website and it does not work. I think it is used just to output the translated string without using ‘echo’.

    pll__
    translates a string previously registered with pll_register_string, this is the way I have done it and it works.

    The code should look like this below and without <ul> on the end as you’ve got it:

    <?php 
    $textlable = pll__('varietes');
    echo '<div class="related"><h4 class="related-portfolio">' . $textlabel . '</h4>';
    ?>

    I put that as my first answer but used <?php $allrightsreserved = pll__('All Rights Reserved'); ?> as an example as I use it on my website.

    Just try it.

    Morris

    Thread Starter oribrn

    (@oribrn)

    Hi Morris,

    I try:

     $the_query = new WP_Query( $args );
                                    if ( $the_query->have_posts() ) {
                                         $textlable = pll__('varietes');
                                        echo '<div class="related"><h4 class="related-portfolio">' . $textlabel . '</h4><ul>';

    but $textlabel appears outside the h4 heading

    screenshot: https://ibb.co/n8bqC7m

    *** $textlabel = Similar varieties:

    Thank you

    Hi
    Sorry I made a mistake $textlable should have been $textlabel, see below:

    <?php 
    $textlabel = pll__('varietes');
    echo '<div class="related"><h4 class="related-portfolio">' . $textlabel . '</h4>';
    ?>

    This is only the code you need and you don’t need the_query bit.

    Thread Starter oribrn

    (@oribrn)

    I think the problem is the syntax.

    ` $the_query = new WP_Query( $args );
    if ( $the_query->have_posts() ) {
    $textlable = pll_e(‘varietes’);
    echo ‘<div class=”related”><h4 class=”related-portfolio”>’ . $textlable . ‘</h4><ul>’;
    while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo ‘<li>’;
    echo ‘<a href=”‘ . get_permalink() . ‘” title=”‘ . get_the_title() . ‘” rel=”bookmark”>’ . get_the_title() . ‘</a>’;
    echo ‘</li>’;
    }
    echo ‘</ul></div>’;
    }
    wp_reset_postdata();`

    In frontent, The string translation appears outside the h4 heading

    • This reply was modified 4 years, 3 months ago by oribrn.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom string translation syntax’ is closed to new replies.