iflookzkill
iflookzkill

Reputation: 25

php variable inside href inside if statement

I am trying to make a thumbnail image clickable so that when clicked, it shows the full size image, but I keep getting a PHP error and I'm not sure why. This is a Wordpress site. I suspect it has something to do with the variable that's inside the URL, but I need some guidance. I've searched stack for almost 8 hours now...Here is my code:

if ( has_post_thumbnail() ) {
    echo '<a href="'get_the_post_thumbnail_url($post_id, 'full');'">';
    the_post_thumbnail('cb-thumb-600-crop');
    echo '</a>';
        } else {

Upvotes: 0

Views: 82

Answers (3)

I. Majid
I. Majid

Reputation: 21

The problem is on this line:

echo  '<a href="'get_the_post_thumbnail_url($post_id, 'full');'">';

You forgot the dots between the single quotes near "get_" and ");"

It should look something like this:

echo '<a href="' . get_the_post_thumbnail_url($post_id, 'full') . '">';

Good luck and keep coding! :)

Upvotes: 0

remedcu
remedcu

Reputation: 526

Try This:

if ( has_post_thumbnail() ) {
$anything=get_the_post_thumbnail_url($post_id, 'full');
$anythings=the_post_thumbnail('cb-thumb-600-crop');
echo '<a href="'.$anything.'">'.$anythings.'</a>';
    } else {

Upvotes: 0

Jed
Jed

Reputation: 1074

I think what's wrong on your code is this:

echo '<a href="'get_the_post_thumbnail_url($post_id, 'full');'">';

should be:

echo '<a href="' . get_the_post_thumbnail_url($post_id, 'full') . '">';

Upvotes: 1

Related Questions