Php line inside alt inside php echo

I am using Wordpress + WPML for translation. I need to insert a string (to be able to translate later) inside the ALT that is inside the php echo ... I tried using '' to split the html from php, but it seems that I am missing something.

Putting this code inside alt:

Gives an error message.

Parse error: syntax error, unexpected '''' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'

      

This is the code:

 // START Condition Icon 1 
 $ico1 = get_post_meta($post->ID,'wpcf-ico-diving', true); 
 if ( $ico1) 
 {
    echo '<li alt="'<?php
    _e('Scuba Diving Tulum', 'aguaclaraproject');?>'" class="i1 icommon"></li>';
 }
 else {
   // Show Nothing 
 } // END

      

I appreciate your help to enable me to better understand how php works and to resolve this issue.

+3


source to share


1 answer


You are already in the php script, remove the php tags and link it correctly.

echo '<li alt="'. _e('Scuba Diving Tulum', 'aguaclaraproject') . '" class="i1 icommon"></li>';

      

Or like this:



$alt = _e('Scuba Diving Tulum', 'aguaclaraproject');
echo "<li alt='$alt' class='i1 icommon'></li>";

      

Or finally

$alt = __('Scuba Diving Tulum', 'aguaclaraproject');
echo "<li alt='$alt' class='i1 icommon'></li>";

      

+4


source







All Articles