#40227 closed defect (bug) (invalid)
shortlink shows POST instead of PAGE guid
Reported by: | Darko A7 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7.3 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
original forum topic is here:
https://wordpress.org/support/topic/shows-post-url-form-instead-for-page/
In short: created "page" inside WP Admin > Pages menu, and in it's source code the shortlink displayed is wrong (using form for posts, instead of pages):
wrong:
<link rel='shortlink' href='https://mywebsite.com/?p=995' />
correct:
<link rel='shortlink' href='https://mywebsite.com/?page_id=995' />
proposed fix:
https://wordpress.org/support/reply/8941661/
original code:
if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) { $shortlink = home_url( '/' );
should be:
if ( 'page' === $post->post_type ) { $shortlink = home_url( '?page_id=' . $post_id );
No longer get 404 from the shortlink url @ page's source code.
Thanks!
Change History (8)
#2
@
3 years ago
Hi dd32,
Thanks for your reply!
I have checked my php log and there are 0 notices/warnings etc (and enabling WP_DEBUG/WP_DEBUG_LOG naturally also gave me an empty file without any issues).
As posted @ forum, all the fields in database seems to be correct, including page's GUID, which is in the form of https: / / website.com?page_id=xxx
Not sure really why it is no working, and this is the only "page" I have for now. It is a standard apache server with auto-generated .htaccess file, using predefined permalinks structure (which do work fine, btw). A real puzzle :(
With above modification it works as expected.
I have also tried to change page's GUID inside database to the form https: / / website.com?p=xxx, but it did not work.
#3
@
3 years ago
The guid isn't used for this at all - and no server configurations should affect it. My best guess is that it'd be related to a custom plugin or theme in use.
#4
@
3 years ago
Thanks, strange I have now tested on local server with same theme and most plugins, and it is working there.
I will try to create new page, delete this one, and see if it will work.
#6
@
3 years ago
Well, thanks dd32, I have located the plugin which was causing the issue - Smart404 (yes, I know it is very old, but it still actually works and I have reworked minor portion of the code to be compatible with latest WP versions). It seems that it will need some more refinements :)
Closing this issue as it is not related to the WP core.
Thanks!
Regards
Hi @Darko-A7 and welcome to Trac,
This is by design -
?p=123
will redirect to the correct location for post_id 123 regardless of if it's a post, page, attachment or custom post type.If you're not seeing that redirect happen for you, it sounds like there's something else at play here preventing that, and that's what you should be looking at for debugging.
For reference, here's a live site performing as expected: https://dd32.id.au/?p=8319 (redirects to the page)