I developed a custom post type. On my archive page for each post there is a <button>. The problem is that I can't put the link to the post in question. My button is in my loop.

<button type="button" onclick="window.location.href='<?php get_post_permalink();?>'"> Click here </button>

  • Can I ask why you're using a button like this? A link to a post should be an a element. There's nothing about your code that requires a button. Commented Oct 23, 2023 at 18:47

1 Answer 1


get_post_permalink() only returns the value. You still need to echo it (and escape it for good measure):

<?php echo esc_url( get_post_permalink() );?>
  • Cool thank you :)
    – Thica
    Commented Oct 23, 2023 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.