get_edit_post_link()
Gets the link (URL) to edit post in the admin panel.
Can be used within the WordPress loop or outside of it. Can be used with any post types: page, post, attachment, custom_post_type and revision.
Uses: current_user_can()
Used By: edit_post_link()
1 time — 0.000344 sec (fast) | 50000 times — 0.95 sec (very fast) | PHP 7.0.8, WP 4.6.1
Hooks from the function
Return
String|null
. The edit post link for the given post. Null if the post type does not exist or does not allow an editing UI.
Usage
$edit_link = get_edit_post_link( $id, $context );
- $id(int/WP_Post)
- Post ID or post object, the edit link of which we need to get.
Default: is the global $post - $context(string)
Context in which the link will be used.
display
means that ampersand (&) will be converted to &.''
means to not change the ampersand.
Default: 'display'
Examples
#1 Print the link only if the user has sufficient capability for edit the post
if( current_user_can( 'edit_posts' ) ) { echo '<a href="'. get_edit_post_link(1) .'">Edit</a>'; }
#2 Example of how this function works
echo get_edit_post_link( 1 ); // display: http://example.com/wp-admin/post.php?post=1&action=edit
#3 Display ready link
echo '<a href="' . get_edit_post_link(1) . '">Edit</a>';
Changelog
Since 2.3.0 | Introduced. |