skip to Main Content
<?php the_permalink(); ?>

in the echo, so when the post title is clicked it opens it is respective post link, but on click of post title it is opening this link http://localhost/courses/, Here is my code

echo '<p><a href="<?php the_permalink(); ?>">'.$post->post_title.'</a></p>';

3

Answers


  1. Chosen as BEST ANSWER
    echo '<p><a href="'. get_permalink() .'">'.$post->post_title.'</a></p>';
    

    This code is working, Thankyou


  2. You are declaring PHP code within PHP code. Remove <?PHP ?> declaration tags, as they are not needed, and replace with string combine which is . in PHP.

    End result should be:

    echo '<p><a href="'. get_permalink() .'">'.$post->post_title.'</a></p>';
    

    As mentioned in the other answer, get_permalink() should be used, as it returns not echos. the_permalink() echos the return.

    Login or Signup to reply.
  3. The problem is the_permalink.

    As a general rule (not always correct), the_ will echo, get_ will return.

    So in your case change the_permalink() to get_permalink()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search