This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I want to edit the URL to a specific URL as I can't find the user meta in WordPress nor in the phpMyAdmin in the cPanel.
I want to change this:
if(get_user_meta( $user_id, 'googleplus', $single) !=""){
echo "<br/><a class='author-link g' title='Follow on Google+' href=".get_user_meta( $user_id, googleplus', $single )." target='_blank'>Google+</a>";
}
To:
if(get_user_meta( $user_id, 'googleplus', $single) !=""){
echo "<br/><a class='author-link g' title='Follow on Google+' href="https://example.com" target='_blank'>Google+</a>";
}
And the error is:
syntax error, unexpected 'https' (T_STRING), expecting ',' or ';'
I have tried:
href="<?php echo "http://www.example.com"; ?>"
href="https:\/\/www.example.com"
href="https://www.example.com"
Would appreciate any advice as I have zero knowledge in PHP.
You have an error in using single quoted and double quoted
in your code
change "example.com" to 'example.com'
OR use it like this way \"example.com\" to escape double quoted
The finnal right code will be
if(get_user_meta( $user_id, 'googleplus', $single) !=""){
echo "<br/><a class='author-link g' title='Follow on Google+' href='https://example.com' target='_blank'>Google+</a>";
}
change
echo "<br/><a class='author-link g' title='Follow on Google+' href="https://example.com" target='_blank'>Google+</a>";
to
echo '<br/><a class="author-link g" title="Follow on Google+" href="https://example.com" target="_blank">Google+</a>';
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
Hey below I tried to display my image, it may be from the way I referenced in the src. Any ideas hot to fix? Thanks
(I get Parse error: syntax error, unexpected '<' )
<td><?php echo <img src='"/images/thumbs/.$row['thumb']."';?></td>
more ways... just keep attention on " and ' orders
<td><?php echo '<img src="/images/thumbs/'.$row['thumb'].'"';?></td>
you may also use:
<td><?php echo "<img src=\"/images/thumbs/{$row['thumb']}\"";?></td>
hope to be usefull
A cleaner method:
<?php $foo = $row['thumb'];?>
<td><?php echo '<img src="/images/thumbs/'.$foo.'"';?></td>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Here is the code below. I'm trying to put the default logo using PHP conditions in my wp theme. But it's showing an error. ( Parse error: syntax error, unexpected 'get_template_directory_uri' (T_STRING), expecting ',' or ';' in C:\wamp\www\law\wp-content\themes\digital-pro\header.php on line 64 )
if( has_custom_logo() ){
the_custom_logo();
}
else{
echo '<img src=" '.get_template_directory_uri().'/img/logo.png" alt="">';
}
Try it like this..
if( has_custom_logo() ){
the_custom_logo();
}
else{ ?>
<img src=" <?php echo get_template_directory_uri(); ?>/img/logo.png" alt="">
<?php }
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
So I am getting the following parse error when this file loads:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING)
I have tried everything to work out why and I narrowed it down to the
href=\"start.php?id=<?php echo $res['id'] ?>\"
section of the code. I am sure I left out a ' or " but unsure where as
it all makes sense to me. Can anyone with a keener eye see where I am
going wrong? Thank you.
My code:
<td>
<?php if($res['ndaSent'] == "No") {
echo "<span class=\"buttonTestDisabled\"> Start Test</span>";}
else {
echo "<a class=\"buttonTest\" href=\"start.php?id=<?php echo $res['id']
?>\">Start Test</a> ";}
?>
</td>
Take a look at that. You can't use echo command inside of an echo " " line. Try using ' inside and not \ may help you too from confusion.
<?php if($res['ndaSent'] == "No") {
echo "<span class='buttonTestDisabled'> Start Test</span>";
}else{
echo "<a class='buttonTest' href='start.php?id=".$res['id'].">Start Test</a>';}
?>
</td>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
So I am getting the following parse error when this file loads:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING)
I have tried everything to work out why and I narrowed it down to the
href=\"start.php?id=<?php echo $res['id'] ?>\"
section of the code. I am sure I left out a ' or " but unsure where as it all makes sense to me. Can anyone with a keener eye see where I am going wrong? Thank you.
My code:
<td>
<?php if($res['ndaSent'] == "No") {
echo "<span class=\"buttonTestDisabled\"> Start Test</span>";}
else {
echo "<a class=\"buttonTest\" href=\"start.php?id=<?php echo $res['id'] ?>\">Start Test</a> ";}
?>
</td>
echo "<a class=\"buttonTest\" href=\"start.php?id=<?php echo $res['id'] ?>\">Start Test</a> ";
}
Is incorrect, you are closing the PHP code before you are done with the PHP code. And $res['id'] cannot be in your echo like that, you should interpolate the variable correctly in the string. Remove the starting and closing tag inside the echo like this:
echo "<a class=\"buttonTest\" href=\"start.php?id={$res['id']}\">Start Test</a> ";
Please check this awesome guide on how to fix these kind of syntax errors.
You cant had snippet in echo use simple string concatenation
<td>
<?php if($res['ndaSent'] == "No") {
echo "<span class=\"buttonTestDisabled\"> Start Test</span>";}
else {
echo "<a class=\"buttonTest\" href=\"start.php?id=".$res['id']."\">Start Test</a> ";}
?>
</td>
Try this
echo "<a class=\"buttonTest\" href=\"start.php?id=" . $res['id'] . " \">Start Test</a> ";}
This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 8 years ago.
I want my link class to be a variable (I am using the filtering system Isotope).
$categories = get_categories($args);
foreach($categories as $category) {
$name = '.'.$category->name;
echo '<a href="#" data-filter=$name>'; //$name does not work here
echo $category->name;
echo '</a>';
echo ' / ';
}
My $name is only displayed as $name in the browser and not the category name I want. Outside the data-filter echoing $name gives all the categories as expected. Is there a way to solve this problem with putting the $name in the data-filter? If the answer is too difficult, please point me to the right direction of what I should do to fix this problem myself please.
Thanks!
Strings in single quotes do not do variable expansion. You have to change it to something like this:
echo '<a href="#" data-filter='.$name.'>';
An alternative without the need for concatenation would be:
echo "<a href=\"#\" data-filter=$name>";
Or, more elegant in my eyes:
echo sprintf('<a href="#" data-filter=%s>', $name);
Also I guess you have to add double quotes around that data-filter attributes content...