I’m getting this syntax error: Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ on line 18 on this page.
I think it’s the ‘first published’ line that could be the problem. Any suggestions?
Thanks – Tara
<?php
$days = round((date('U') - get_the_time('U')) / (60*60*24));
if ($days==0) {
echo "Published today |";
}
elseif ($days==1) {
echo "Published yesterday |";
}
else {
echo "First published " the_time('F - j - Y') " |";
}
?>
Last updated at <?php the_time('g:i a'); ?> on <?php the_time('l, F jS, Y') ?> by <?php the_author(); ?>
Your issue is this:
The other answers that suggest concatenation are all wrong. the_time(), in WordPress, will echo, so you need to split this in multiple calls:
Alternatively, concatenate but using get_the_time():
If this is indeed code from WordPress, and the_time() echoes by itself, yes, then you need to put the echoes on separate lines:
Sidenote:
When the parser complains that you are missing a semicolon (;), I find there are two very common reasons:
1: The error you have here; the parser finds and illegal character on the line. Having a function call right after a string literal (without a line terminator, like semi-colon, or an operator like . between them) will cause the parser output an error, and the parser will then guess that maybe you forgot to terminate the line here.
2: You actually forgot to terminate the line. But then the parser will complain about the line on which it finds the illegal character, and usually, you will want to tack the semi-colon on at the end of the line above:
Instead of
Try
By using get_the_time() instead of the_time(), you can echo this concatenated with the rest of your string instead of having to break it into multiple lines. Where WordPress functions like the_time() echo their results, there is often a “get” version that returns the value without echoing it.
You need to use the concat operator (the dot).
There are two ways to fix this.
The first is the same way everyone else did it: String concatenation:
The other way is to add commas between each string. The reason this works is because
echo
takes multiple arguments.I don’t know whether it’s faster than string concatenation, though.