edit_term_link() WordPress Function

The edit_term_link() function is used to generate a link to the edit page for a given term. This function can be used in conjunction with the get_term_link() function to create a link to the edit page for a specific term. The edit_term_link() function accepts two parameters: the term ID and the taxonomy. The term ID is the ID of the term you want to edit, and the taxonomy is the name of the taxonomy that the term belongs to. If you want to generate a link to the edit page for a specific term, you can use the following code: This will output a link to the edit page for the term with an ID of 123 in the category taxonomy.

edit_term_link( string $link = '', string $before = '', string $after = '', int|WP_Term|null $term = null, bool $echo = true ) #

Displays or retrieves the edit term link with formatting.


Parameters

$link

(string)(Optional) Anchor text. If empty, default is 'Edit This'.

Default value: ''

$before

(string)(Optional) Display before edit link.

Default value: ''

$after

(string)(Optional) Display after edit link.

Default value: ''

$term

(int|WP_Term|null)(Optional) Term ID or object. If null, the queried object will be inspected.

Default value: null

$echo

(bool)(Optional) Whether or not to echo the return.

Default value: true


Top ↑

Return

(string|void) HTML content.


Top ↑

Source

File: wp-includes/link-template.php

function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
	if ( is_null( $term ) ) {
		$term = get_queried_object();
	} else {
		$term = get_term( $term );
	}

	if ( ! $term ) {
		return;
	}

	$tax = get_taxonomy( $term->taxonomy );
	if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
		return;
	}

	if ( empty( $link ) ) {
		$link = __( 'Edit This' );
	}

	$link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>';

	/**
	 * Filters the anchor tag for the edit link of a term.
	 *
	 * @since 3.1.0
	 *
	 * @param string $link    The anchor tag for the edit link.
	 * @param int    $term_id Term ID.
	 */
	$link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after;

	if ( $echo ) {
		echo $link;
	} else {
		return $link;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More