Created
February 1, 2024 13:55
-
-
Save cdevroe/929f7f071c61aa94fcd8fd3e1d81796e to your computer and use it in GitHub Desktop.
A WordPress filter to change a post's GUID from ?p=int to its permalink (use with caution)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created for Colin Devroe's personal website: cdevroe.com | |
* It was not his intent that anyone else would use this. | |
* Please refer to the Migrating WordPress doc which | |
* emphasizes to **never update guids** | |
* https://developer.wordpress.org/advanced-administration/upgrade/migrating/#important-guid-note | |
**/ | |
function namespace_set_guid_to_permalink( $guid, $id ) { | |
if ( !is_feed() ) return $guid; | |
if ( strpos( $guid, '?p=' ) > 0 ) return get_the_permalink( $id ); | |
} | |
add_filter( 'get_the_guid', 'namespace_set_guid_to_permalink', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment