The get_the_guid WordPress PHP filter allows you to modify the Global Unique Identifier (GUID) of a post.
Usage
add_filter('get_the_guid', 'your_custom_function', 10, 2); function your_custom_function($post_guid, $post_id) { // your custom code here return $post_guid; }
Parameters
$post_guid
(string) – Global Unique Identifier (GUID) of the post.$post_id
(int) – The post ID.
More information
See WordPress Developer Resources: get_the_guid
Examples
Add a custom prefix to the GUID
Add a custom prefix to the GUID for all posts.
add_filter('get_the_guid', 'custom_prefix_guid', 10, 2); function custom_prefix_guid($post_guid, $post_id) { $post_guid = 'custom_prefix-' . $post_guid; return $post_guid; }
Change the GUID format
Change the GUID format to include the post ID and the current date.
add_filter('get_the_guid', 'change_guid_format', 10, 2); function change_guid_format($post_guid, $post_id) { $current_date = date('Y-m-d'); $post_guid = "http://yourwebsite.com/?p={$post_id}&date={$current_date}"; return $post_guid; }
Add a custom domain to the GUID
Replace the current domain in the GUID with a custom domain.
add_filter('get_the_guid', 'custom_domain_guid', 10, 2); function custom_domain_guid($post_guid, $post_id) { $post_guid = str_replace('http://yourwebsite.com', 'http://customdomain.com', $post_guid); return $post_guid; }
Update GUID only for a specific post type
Update the GUID format only for a specific post type, e.g., “product”.
add_filter('get_the_guid', 'specific_post_type_guid', 10, 2); function specific_post_type_guid($post_guid, $post_id) { $post_type = get_post_type($post_id); if ($post_type == 'product') { $post_guid = "http://yourwebsite.com/product/{$post_id}"; } return $post_guid; }
Add a custom suffix to the GUID
Add a custom suffix to the GUID for all posts.
add_filter('get_the_guid', 'custom_suffix_guid', 10, 2); function custom_suffix_guid($post_guid, $post_id) { $post_guid = $post_guid . '-custom_suffix'; return $post_guid; }