maha2
maha2

Reputation: 23

Php string inside alt inside php echo

Im using Wordpress + WPML to translate. I need to insert a string (to be able of translating later) inside of a ALT that is inside of a php echo... I have tried using '' to separate html from php but seems that I'm missing something.

Putting this code inside the alt:

Gives an error.

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 allow me understand better how php works and solve this issue.

Upvotes: 3

Views: 373

Answers (1)

Kevin
Kevin

Reputation: 41885

You're already inside the php script, remove the php tags and concatenate it properly.

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 lastly:

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

Upvotes: 4

Related Questions