On this page
edit_post_link( string $text = null, string $before = '', string $after = '', int|WP_Post $post, string $class = 'post-edit-link' )
Displays the edit post link for post.
Parameters
$textstring Optional-
Anchor text. If null, default is 'Edit This'.
Default:
null $beforestring Optional-
Display before edit link.
Default:
'' $afterstring Optional-
Display after edit link.
Default:
'' $postint|WP_Post Optional-
Post ID or post object. Default is the global
$post. $classstring Optional-
Add custom class to link. Default
'post-edit-link'.Default:
'post-edit-link'
More Information
Displays a link to edit the current post, if a user is logged in and allowed to edit the post. Can be used within The Loop or outside of it. If outside the loop, you’ll need to pass the post ID. Can be used with pages, posts, attachments, and revisions.
Use get_edit_post_link to retrieve the url.
Source
File: wp-includes/link-template.php. View all references
function edit_post_link( $text = null, $before = '', $after = '', $post = 0, $class = 'post-edit-link' ) {
$post = get_post( $post );
if ( ! $post ) {
return;
}
$url = get_edit_post_link( $post->ID );
if ( ! $url ) {
return;
}
if ( null === $text ) {
$text = __( 'Edit This' );
}
$link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>';
/**
* Filters the post edit link anchor tag.
*
* @since 2.3.0
*
* @param string $link Anchor tag for the edit link.
* @param int $post_id Post ID.
* @param string $text Anchor text.
*/
echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after;
}
Hooks
- apply_filters( 'edit_post_link',
string $link ,int $post_id ,string $text ) -
Filters the post edit link anchor tag.
Related
Uses
| Uses | Description |
|---|---|
| get_edit_post_link() wp-includes/link-template.php | Retrieves the edit post link for post. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
| esc_url() wp-includes/formatting.php | Checks and cleans a URL. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/edit_post_link