Using WordPress ‘get_edit_term_link()’ PHP function

The get_edit_term_link() WordPress PHP function retrieves the URL for editing a given term.

Usage

$edit_term_url = get_edit_term_link($term, $taxonomy = '', $object_type = '');

Parameters

  • $term (int|WP_Term|object) (Required): The ID or term object whose edit link will be retrieved.
  • $taxonomy (string) (Optional): Taxonomy. Defaults to the taxonomy of the term identified by $term. Default: ”.
  • $object_type (string) (Optional): The object type. Used to highlight the proper post type menu on the linked page. Defaults to the first object_type associated with the taxonomy. Default: ”.

More information

See WordPress Developer Resources: get_edit_term_link

Examples

Basic usage

Retrieve the edit link for a term with ID 15 in the ‘category’ taxonomy.

$edit_link = get_edit_term_link(15, 'category');
echo $edit_link; // Output: edit link URL

Using a WP_Term object

Retrieve the edit link for a term with the WP_Term object.

$term = get_term(15, 'category');
$edit_link = get_edit_term_link($term);
echo $edit_link; // Output: edit link URL

Specifying object type

Retrieve the edit link for a term with ID 15 in the ‘category’ taxonomy and the ‘post’ object type.

$edit_link = get_edit_term_link(15, 'category', 'post');
echo $edit_link; // Output: edit link URL

Using with a custom taxonomy

Retrieve the edit link for a term with ID 10 in the custom taxonomy ‘my_custom_taxonomy’.

$edit_link = get_edit_term_link(10, 'my_custom_taxonomy');
echo $edit_link; // Output: edit link URL

Retrieve the edit link for a term with ID 15 in the ‘category’ taxonomy and display it in an anchor tag.

$edit_link = get_edit_term_link(15, 'category');
echo '<a href="' . esc_url($edit_link) . '">Edit term</a>'; // Output: <a href="edit link URL">Edit term</a>