page_link filter allows you to do change the permalink returned for the current page when using
get_permalink() is used with pages, it employs
get_page_link(), which respects the
page_on_front options. This means that if the current page is set as your front page, the permalink returned will be the
page_link accepts 3 arguments:
$linkthe page link
$post_idthe page id
$samplewhether or not to return a ‘sample’ permalink
Let’s say that for some reason, you have a page set as your front page but you want to return the page’s actual permalink when using
get_permalink(). The following checks the
page_on_front options to see if there’s a match, and if there is, returns the actual permalink instead.
Note: this has the possibility of wreaking havoc on how WordPress determines a ‘Home’ link in menus as well as how the front page may be determined.
View the code example on Gist.Have a suggested improvement? You can fork the Gist and comment back with the link. If all is agreeable, I’ll merge in your changes. Crowd-sourced documentation FTW!