Skip to content
Advertisement

How to rewrite default php code to a valid echo line output?

I am new to PHP and for the development of a WordPress theme I need to re-write the following line of php/html code so that I can use it in my functions.php. I found out that I would need to rewrite it as an “echo” call, but I am always getting an error because my syntax is wrong.

This is the line we’re talking about:

JavaScript

I’ve tried several times, e.g.

JavaScript

but I am doing something wrong in encapsulating things I guess.

EDIT: As requested, the part of the functions.php

JavaScript

Advertisement

Answer

There is a semicolon in the middle of your line

echo '<div class="'. post_class("brick_item" . $termString); .'" onclick=location.href="'. the_permalink() .'">';

should be

echo '<div class="'. post_class("brick_item" . $termString) .'" onclick=location.href="'. the_permalink() .'">';

semicolons signify end of line in php, thus your code did first execute

echo '<div class="'. post_class("brick_item" . $termString);

which is fine, but only half of what you want. Then php tries executing

.'" onclick=location.href="'. the_permalink() .'">';

but doesn’t know what to do with a dot at the start of the line. Dot means append string before to string after, but there is nothing before, so it’s a compile error. You can also just add another echo to the second line instead of the dot

echo '" onclick=location.href="'. the_permalink() .'">';

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement