edit_post_link()
Displays the edit post link for a post, if the user is allowed to change the post.
Must be used inside the Loop of WordPress.
Uses: get_edit_post_link()
1 time — 0.003579 sec (very slow) | 50000 times — 7.28 sec (fast) | PHP 7.1.11, WP 4.9.5
Hooks from the function
Return
null
. Ничего (null).
Usage
edit_post_link( $text, $before, $after, $post, $css_class );
- $text(string)
- Anchor text. If null. Default null.
Default: 'Edit This' - $before(string)
- Display before edit link.
Default: '' - $after(string)
- Display after edit link.
Default: '' - $post(int|WP_Post)
- Post ID or post object.
Default: global $post - $css_class(string)
- Add custom class to link.
Default: 'post-edit-link'
Examples
#1 Display the link to edit the post
The edit post link will be displayed only for users who can edit the post (posts).
<?php edit_post_link(); ?>
Output:
<a class="post-edit-link" href="https://example.com/wp-admin/post.php?post=19&action=edit">Edit</a>
#2 Change the text of the link and enclose it in html tag <p>
<?php edit_post_link('edit', '<p>', '</p>'); ?>
Changelog
Since 1.0.0 | Introduced. |
Since 4.4.0 | The $css_class argument was added. |