7

Both functions return permalink to the post or page by it's ID. What are the differences and which of these functions should I use in which cases?

7

When i explored the WordPress core for this answer i found that get_permalink() function internally calls get_page_link() function for getting permalink of page and it calls get_post_permalink() function to get permalink of post.

Therefore either you use get_permalink() function or get_page_link() function, you will get same result.

The difference between these two is get_page_link() function handles page_on_front page set in back end whereas get_post_permalink() function do not consider it.

  • I just discovered that the result is not exactly the same, because get_page_link returns "page_id=XX", while get_permalink returns nice url like "page/subpage". – Robert Zelník Aug 25 '13 at 5:31
  • @RobertZelník ok. Can you tell me what's your permalink structure? – Vinod Dalvi Aug 25 '13 at 6:50
  • It is strange but I can not reproduce the issue anymore. Something has probably changed and now both get_page_link and get_permalink return "page_id=XX". – Robert Zelník Aug 26 '13 at 18:37
2

In my opinion get_page_link is for displaying the link and get_permalink is not for displaying the link.

WordPress Codex says: get_permalink: It does NOT display the permalink.

  • 2
    This is a common property of all functions starting with "get_" - both get_page_link and get_permalink do not display anything, they just return a value. If we want to display the result, we can add <?php echo get_page_link($id) ?>. – Robert Zelník Aug 25 '13 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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