Question

i am trying to insert a link in an echoed line, regular links work, but not this one, cant figure it out what's wrong

    if($gallery_images !=  ''){ 
        foreach ($gallery_images as $gallery_image){
            $thumb = wp_get_attachment_image_src($gallery_image[SN.'gallery_post_image']['id'], 'post-thumb', false);
            echo '<li><a  <a  href="'.the_permalink().'"><img src="'.$thumb[0].'" alt="'.$gallery_image[SN.'gallery_post_title'].'" /></a><p class="flex-caption">'.$gallery_image[SN.'gallery_post_title'].'</p></li>';
        }
    }
Était-ce utile?

La solution

the_permalink() is a not a return function, it echoes the permalink. Replace it with get_permalink, which returns the permalink.

 if($gallery_images !=  ''){ 
        foreach ($gallery_images as $gallery_image){
            $thumb = wp_get_attachment_image_src($gallery_image[SN.'gallery_post_image']['id'], 'post-thumb', false);
            echo '<li><a  <a  href="'.get_permalink().'"><img src="'.$thumb[0].'" alt="'.$gallery_image[SN.'gallery_post_title'].'" /></a><p class="flex-caption">'.$gallery_image[SN.'gallery_post_title'].'</p></li>';
        }
    }

Autres conseils

Your first problem is that. You don't include a function on a string that way.

echo '<li><a  href="**<?php the_permalink(); ?>**">

Try this:

echo '<li><a  href="'.the_permalink().'">

Then

.$gallery_image[SN.'gallery_post_title'].

You got a syntax error there.

SN.'gallery_post_title' // notice SN

It's fine if you define SN though.

Also, why do you have a close curly brace }?

Did you just copy and paste your code here sloppily or is that intentional? It's confusing if it is.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top