Displays the edit post link for post.
Parameters
$text
stringoptional- Anchor text. If null, default is ‘Edit This’.
Default:
null
$before
stringoptional- Display before edit link.
Default:
''
$after
stringoptional- Display after edit link.
Default:
''
$post
int|WP_Postoptional- Post ID or post object. Default is the global
$post
. $css_class
stringoptional- Add custom class to link. Default
'post-edit-link'
.Default:
'post-edit-link'
Source
function edit_post_link( $text = null, $before = '', $after = '', $post = 0, $css_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( $css_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.
Display edit link wrapped in a paragraph tag, with custom CSS classes on the link itself.
Display Edit in Paragraph Tag
Displays edit post link, with link text “edit”, in a paragraph () tag.
Default Usage
Displays edit post link using defaults.