Title: edit_link
Published: April 25, 2014
Last modified: February 24, 2026

---

# edit_link( int $link_id ): int|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#wp--skip-link--target)

Updates or inserts a link using values provided in $_POST.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#parameters)󠁿

 `$link_id`intoptional

ID of the link to edit. Default 0.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#return)󠁿

 int|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) Value
0 or [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) on 
failure. The link ID on success.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#source)󠁿

    ```php
    function edit_link( $link_id = 0 ) {
    	if ( ! current_user_can( 'manage_links' ) ) {
    		wp_die(
    			'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
    			'<p>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '</p>',
    			403
    		);
    	}

    	$_POST['link_url']   = esc_url( $_POST['link_url'] );
    	$_POST['link_name']  = esc_html( $_POST['link_name'] );
    	$_POST['link_image'] = esc_html( $_POST['link_image'] );
    	$_POST['link_rss']   = esc_url( $_POST['link_rss'] );
    	if ( ! isset( $_POST['link_visible'] ) || 'N' !== $_POST['link_visible'] ) {
    		$_POST['link_visible'] = 'Y';
    	}

    	if ( ! empty( $link_id ) ) {
    		$_POST['link_id'] = $link_id;
    		return wp_update_link( $_POST );
    	} else {
    		return wp_insert_link( $_POST );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/bookmark.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/bookmark.php#L28)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/bookmark.php#L28-L51)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_update_link()](https://developer.wordpress.org/reference/functions/wp_update_link/)`wp-admin/includes/bookmark.php` |

Updates a link in the database.

  | 
| [wp_insert_link()](https://developer.wordpress.org/reference/functions/wp_insert_link/)`wp-admin/includes/bookmark.php` |

Inserts a link into the database, or updates an existing link.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [wp_die()](https://developer.wordpress.org/reference/functions/wp_die/)`wp-includes/functions.php` |

Kills WordPress execution and displays HTML page with an error message.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#)

| Used by | Description | 
| [add_link()](https://developer.wordpress.org/reference/functions/add_link/)`wp-admin/includes/bookmark.php` |

Adds a link using values provided in $_POST.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/edit_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fedit_link%2F)
before being able to contribute a note or feedback.