Translate WordPress block with <?php _e(

I have made some block custom in my wordpress theme. I did have to edit the shortcode.php file to add a price table. The thing I just realize is that I need those words ( From , /DAY , Book ) being translated though the .po file of my theme. So I have tried to add this line to replace the word ( “From” for example ). But I have a error code, I guess I don’t have a good syntax here but can’t find the right one. Can you Help?

Here is the original code

Read More
/*CUSTOM PRICE*/

}elseif($type === 'content_block_custom_price'){

$result = '<div class="featurecustom text-center">';

$result .=  '<div class="thumbnail">
              <img src="'.AUTORENT_IMAGE.''.$img.'" alt="">

             </div>

            <p class="titlecustom">'.$title.'</p> 
            <p class="fromprice"> From</p>           
            <span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="fromprice">/ DAY</span>  
            <hr>        
            <p class="customdescription">'.$des.'</p>

            <a href="'.$linktypebutton.'"> <div class="bookingbutton" style="vertical-align:middle"><span>BOOK </span></div> </a>

            ';

$result .= '</div>';


return $result;

/* CUSTOM PRICE*/

Here is the bad code i try to have my word translate

/*CUSTOM PRICE*/

}elseif($type === 'content_block_custom_price'){

$result = '<div class="featurecustom text-center">';

$result .=  '<div class="thumbnail">
              <img src="'.AUTORENT_IMAGE.''.$img.'" alt="">

             </div>

            <p class="titlecustom">'.$title.'</p> 
            <p class="fromprice"> <?php _e('From','themename'); ?></p>           
            <span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="fromprice"><?php _e('/DAY','themename'); ?></span>  
            <hr>        
            <p class="customdescription">'.$des.'</p>

            <a href="'.$linktypebutton.'"> <div class="bookingbutton" style="vertical-align:middle"><span><?php _e('Book','themename'); ?> </span></div> </a>

            ';

$result .= '</div>';


return $result;

/* CUSTOM PRICE*/

Post solved problem question : One I have new entries such as “Book” ” FROM” and “/DAY”, I guess I will have to creat them into the poedit file? Or will they be automatically added?

Thanks 🙂

Related posts

1 comment

  1. Here is the good code (just inserting the gettex like this '. __("From","theme name").':

    /*CUSTOM PRICE*/
    
    }elseif($type === 'content_block_custom_price'){
    
    $result = '<div class="featurecustom text-center">';
    
    $result .=  '<div class="thumbnail">
                  <img src="'.AUTORENT_IMAGE.''.$img.'" alt="">
    
                 </div>
    
                <p class="titlecustom">'.$title.'</p> 
                <p class="fromprice"> '. __("From","theme name").'</p>           
                <span class="pricenumber">'.$pricetype.'<sup>€</sup></span><span class="from price">'. __("/DAY","theme name") .'</span>  
                <hr>        
                <p class="customdescription">'.$des.'</p>
    
                <a href="'.$linktypebutton.'"> <div class="bookingbutton" style="vertical-align:middle"><span>'. __("Book","themename"); .' </span></div> </a>
    
                ';
    
    $result .= '</div>';
    
    
    return $result;
    
    /* CUSTOM PRICE*/
    

    For translation of themes & plugins there is a very effective and easy free plugin: Loco Translate

    This plugin is going to scan your theme for new items to translate…

Comments are closed.