Title: get_post_reply_link
Published: April 25, 2014
Last modified: May 20, 2026

---

# get_post_reply_link( array $args = array(), int|WP_Post $post = null ): string|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#wp--skip-link--target)

Retrieves HTML content for reply to post link.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#parameters)󠁿

 `$args`arrayoptional

Override default arguments.

 * `add_below` string
 * The first part of the selector used to identify the comment to respond below.
   
   The resulting value is passed as the first parameter to addComment.moveForm(),
   concatenated as $add_below-$comment->comment_ID. Default is `'post'`.
 * `respond_id` string
 * The selector identifying the responding comment. Passed as the third parameter
   to addComment.moveForm(), and appended to the link URL as a hash value.
    Default`'
   respond'`.
 * `reply_text` string
 * Text of the Reply link. Default is ‘Leave a Comment’.
 * `login_text` string
 * Text of the link to reply if logged out. Default is ‘Log in to leave a Comment’.
 * `before` string
 * Text or HTML to add before the reply link.
 * `after` string
 * Text or HTML to add after the reply link.

Default:`array()`

`$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
optional

Post ID or [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
object the comment is going to be displayed on.
 Default current post.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#return)󠁿

 string|false Link to show comment form on success. False if comments are closed.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#source)󠁿

    ```php
    function get_post_reply_link( $args = array(), $post = null ) {
    	$defaults = array(
    		'add_below'  => 'post',
    		'respond_id' => 'respond',
    		'reply_text' => __( 'Leave a Comment' ),
    		'login_text' => __( 'Log in to leave a Comment' ),
    		'before'     => '',
    		'after'      => '',
    	);

    	$args = wp_parse_args( $args, $defaults );

    	$post = get_post( $post );

    	if ( ! comments_open( $post->ID ) ) {
    		return false;
    	}

    	if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
    		$link = sprintf(
    			'<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
    			wp_login_url( get_permalink() ),
    			$args['login_text']
    		);
    	} else {
    		$onclick = sprintf(
    			'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )',
    			$args['add_below'],
    			$post->ID,
    			$args['respond_id']
    		);

    		$link = sprintf(
    			"<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>",
    			get_permalink( $post->ID ) . '#' . $args['respond_id'],
    			$onclick,
    			$args['reply_text']
    		);
    	}

    	$post_reply_link = $args['before'] . $link . $args['after'];

    	/**
    	 * Filters the formatted post comments link HTML.
    	 *
    	 * @since 2.7.0
    	 *
    	 * @param string      $post_reply_link The HTML-formatted post comments link.
    	 * @param int|WP_Post $post            The post ID or WP_Post object.
    	 */
    	return apply_filters( 'post_comments_link', $post_reply_link, $post );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/comment-template.php#L1915)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/comment-template.php#L1915-L1966)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#hooks)󠁿

 [apply_filters( ‘post_comments_link’, string $post_reply_link, int|WP_Post $post )](https://developer.wordpress.org/reference/hooks/post_comments_link/)

Filters the formatted post comments link HTML.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_login_url()](https://developer.wordpress.org/reference/functions/wp_login_url/)`wp-includes/general-template.php` |

Retrieves the login URL.

  | 
| [comments_open()](https://developer.wordpress.org/reference/functions/comments_open/)`wp-includes/comment-template.php` |

Determines whether the current post is open for comments.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [is_user_logged_in()](https://developer.wordpress.org/reference/functions/is_user_logged_in/)`wp-includes/pluggable.php` |

Determines whether the current visitor is a logged in user.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [get_permalink()](https://developer.wordpress.org/reference/functions/get_permalink/)`wp-includes/link-template.php` |

Retrieves the full permalink for the current post or post ID.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 7 more](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#)

| Used by | Description | 
| [post_reply_link()](https://developer.wordpress.org/reference/functions/post_reply_link/)`wp-includes/comment-template.php` |

Displays the HTML content for reply to post link.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_reply_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_reply_link%2F)
before being able to contribute a note or feedback.