I asked a very similar question earlier today (http://wordpress.stackexchange.com/questions/30392/how-to-get-the-original-post-id-of-a-static-home-page) and thought I had the answer, but now it appears otherwise.
If I have a post/page with the original permalink of http://mydomain.com/blog/my-post/
for example, and I set that as the static home page of the blog, I am unable to get the original permalink of that page when I visit it, since WP only returns the root (site_url()
essentially) permalink and redirects me there, since it is now set as the home page.
How can I retrieve the ORIGINAL permalink? get_option('page_on_front')
doesn’t work because it will just return the blog root url, such as http://mydomain.com/blog/
. I need to fetch the full original unaltered permalink of the currently-set static home page.
Hope that’s clear… thanks all!
Edit: Wow. I mistyped a bunch the first time around. Hopefully nobody read that. All corrected now. /edit
I went code spelunking… 🙂
Short version, the workaround would be this:
If you look into link-template.php in the WordPress core, you can kind of trace the path that happens. Calling the_permalink() leads to get_page_link(), which returns the permalink of the post/page ID you pass it. However, one of the checks that get_page_link() does is to see if the requested ID is currently set as ‘page_on_front’. If it is, a static value of ‘/’ is returned as the permalink. If it’s not, the function _get_page_link() is called instead. Note the underscore on the front of the function.
In order to solve the issue, I cut past the_permalink() and get_page_link() and went straight to _get_page_link().
There may be some security issue or reason for this behavior to be default that I’m not aware of, but it works…