Using WordPress ‘comment_guid()’ PHP function

The comment_guid() WordPress PHP function is used to display the feed GUID (Globally Unique Identifier) for the current comment.


Here’s a simple use case for the comment_guid() function. Let’s say we have a comment ID, and we want to fetch and display the feed GUID for that particular comment.

// Assuming we have a comment ID
$comment_id = 15;

// Using comment_guid() to display the feed GUID


  • $comment_id int|WP_Comment Optional – This optional parameter can either be a comment object or a comment ID. If not provided, it defaults to the global comment object. Default: null.

More information

See WordPress Developer Resources: comment_guid()

This function is a part of the WordPress core and is not deprecated. It is defined in wp-includes/comment-template.php. Related functions include get_comment_guid(), which retrieves the comment GUID instead of displaying it.


Displaying Comment GUID for a Specific Comment

This will display the GUID for the comment with the ID of 15.

$comment_id = 15;
comment_guid($comment_id); // Displays the GUID for comment 15

Displaying Comment GUID Without Specifying a Comment

In the absence of a specific comment ID or object, the function will default to the global comment object.

comment_guid(); // Displays the GUID for the current global comment

Displaying Comment GUID Inside a Comment Loop

This will display the GUID for each comment in a loop.

if (have_comments()) {
    while (have_comments()) {

Using Comment Object Instead of ID

You can also use a comment object instead of a comment ID.

$comment = get_comment(15);

Checking If Comment GUID Is Empty

Before displaying the comment GUID, you might want to check if it’s not empty.

$comment_id = 15;
if (get_comment_guid($comment_id) != '') {