my php echo statement for an <a href=”#”> is making the url visible

I am going by this tutorial (https://redvinestudio.com/how-to-build-isotope-portfolio-in-your-wordpress-theme/), and when I am working on the part where the portfolio items are displayed as links, the url that the link leads to is being displayed above the item. Below is the prescribed code:

echo '<div class="all portfolio-item '. $tax .'">';
echo '<a href="'. the_permalink() .'" title="'. the_title_attribute() .'">';
echo '<div class="thumbnail">'. the_post_thumbnail('thumbnail') .'</div>';
echo '<h2>'. the_title() .'</h2>';
echo '</a>';
/*echo '<div>'. the_excerpt() .'</div>';*/
echo '</div>';

Related posts

2 comments

  1. You can’t use the_permalink() within an echo, because it echoes data itself. Instead, you need to use get_permalink(). You also need to modify the_title_attribute() to avoid a duplicated echo there:

    echo '<a href="'. get_permalink() .'" title="'. the_title_attribute( 'echo=0' ) .'">';
    

    EDIT: You need to comb through your code to remove all instances of code that is echoing content within an echo. This includes the_title(), the_post_thumbnail(), etc.

  2. the_permalink() will always echo the URL of the object, which means you’re telling it to echo twice. Change it to get_permalink() and it should work.

Comments are closed.