Search code examples
phpwordpresspermalinks

Which is better to get current page link - get_permalink() or get_page_link()?


For get_permalink() I saw that there's a complication when not using with loops, https://developer.wordpress.org/reference/functions/get_permalink/

get_page_link() looks straight forward to me, https://developer.wordpress.org/reference/functions/get_page_link/

So which is better actually?


Solution

  • get_page_link() is specific to the page post type, there is also get_attachment_link() and get_post_permalink() for attachments and posts respectively.

    get_the_permalink() checks the post type and uses the appropriate function from above ones.

    That's why i prefer get_permalink() or get_the_permalink()