WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/edit post link

Description

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.

Usage

 <?php edit_post_link$link$before$after$id$class ); ?> 

Parameters

$link
(string) (optional) The link text.
Default: __('Edit This')
$before
(string) (optional) Text to put before the link text.
Default: None
$after
(string) (optional) Text to put after the link text.
Default: None
$id
(integer) (optional) Post ID (added in WordPress 2.8).
Default: None
$class
(string) (optional) CSS class name for the link (added in WordPress 4.4).
Default: post-edit-link

Examples

Default Usage

Displays edit post link using defaults.

<?php edit_post_link(); ?>

Display Edit in Paragraph Tag

Displays edit post link, with link text "edit", in a paragraph (<p>) tag.

<?php edit_post_link('edit', '<p>', '</p>'); ?>

Changelog

  • 4.4 : Added the class parameter.
  • 2.8 : Added the id parameter.
  • Since: 1.0.0

Source File

edit_post_link() is located in wp-includes/link-template.php

Related

Edit Link: edit_post_link(), edit_comment_link(), edit_tag_link(), edit_bookmark_link()

See also index of Function Reference and index of Template Tags.