edit_post_link() WP 1.0.0
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.
Works based on: get_edit_post_link()
1 time = 0.003579s = very slow | 50000 times = 7.28s = fast | PHP 7.1.11, WP 4.9.5
Hooks from the function
Return
Null. Nothing.
Usage
edit_post_link( $text, $before, $after, $id, $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: '' - $id(int/WP_Post)
- Post ID or post object.
Default: global $post - $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 $class argument was added. |
Code of edit_post_link() edit post link WP 5.6
Related Functions
From tag: edit_
More from category: Posts, pages...
- get_permalink()
- get_post_field()
- get_post_status()
- get_post_time()
- get_sample_permalink()
- get_the_content()
- get_the_date()
- get_the_excerpt()
- get_the_ID()
- get_the_modified_date()