edit_post_link

Displays the edit post link for post.

Description

edit_post_link( (constant) $text = null, (string) $before = '', (string) $after = '', (int) $id = 0, (string) $class = 'post-edit-link' ); 

Parameters (5)

0. $text — Optional. (constant) => null
Anchor text. If null, default is Edit This.. Default null.
1. $before — Optional. (string) => ''
Display before edit link. Default empty.
2. $after — Optional. (string) => ''
Display after edit link. Default empty.
3. $id — Optional. (int)
Post ID. Default is the ID of the global $post..
4. $class — Optional. (string) => 'post-edit-link'
Add custom class to link. Default post-edit-link..

Usage

  1. if ( !function_exists( 'edit_post_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Anchor text. If null, default is 'Edit This'. Default null. 
  5. $text = null; 
  6.  
  7. // Optional. Display before edit link. Default empty. 
  8. $before = ''; 
  9.  
  10. // Optional. Display after edit link. Default empty. 
  11. $after = ''; 
  12.  
  13. // Optional. Post ID. Default is the ID of the global `$post`. 
  14. $id = -1; 
  15.  
  16. // Optional. Add custom class to link. Default 'post-edit-link'. 
  17. $class = 'post-edit-link'; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = edit_post_link($text, $before, $after, $id, $class); 
  21.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { 
  2. if ( ! $post = get_post( $id ) ) { 
  3. return; 
  4.  
  5. if ( ! $url = get_edit_post_link( $post->ID ) ) { 
  6. return; 
  7.  
  8. if ( null === $text ) { 
  9. $text = __( 'Edit This' ); 
  10.  
  11. $link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>'; 
  12.  
  13. /** 
  14. * Filters the post edit link anchor tag. 
  15. * @since 2.3.0 
  16. * @param string $link Anchor tag for the edit link. 
  17. * @param int $post_id Post ID. 
  18. * @param string $text Anchor text. 
  19. */ 
  20. echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after;