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?
2 Answers
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". Aug 25, 2013 at 5:31
-
@RobertZelník ok. Can you tell me what's your permalink structure? Aug 25, 2013 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". Aug 26, 2013 at 18:37
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.
-
2This 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) ?>. Aug 25, 2013 at 5:28