WordPress at a glance

edit_term_link() WP 3.1.0

Displays/retrieves edit term link (html tag A), link to edit the specified taxonomy element.

Use get_edit_term_link() to get edit term URL (not A tag).

Is the basis for: edit_tag_link()
Works based on: get_edit_term_link()
Hooks in function
Return

String/null. <a> HTML tag. null when the user has no cap to edit the term.

Usage

edit_term_link( $link, $before, $after, $term, $echo );
$link(string)
Anchor text.
Default: ''
$before(string)
Display before edit link.
Default: ''
$after(string)
Display after edit link.
Default: ''
$term(object)
Term object. If null, the queried object will be inspected.
Default: null
$echo(true/false)
Whether or not to echo the return.
Default: true

Examples

#1 Display link to edit the current term

It is assumed that the link is displayed on a term archive page.

edit_term_link();

// displays:
// <a href="http://example.com/wp-admin/edit-tags.php?action=edit&taxonomy=funccat&tag_ID=154&post_type=func">Edit</a>

#2 Output a link to edit the specified term

$term = get_term( 154 );

edit_term_link( 'Edit term', '', '', $term, 0 );

// displays:
// <a href="http://example.com/wp-admin/edit-tags.php?action=edit&taxonomy=funccat&tag_ID=154&post_type=func">Edit term</a>

Code of edit term link: wp-includes/link-template.php WP 5.2.1

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

	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;
	}
}

Related Functions

From tag: Link (tag A in HTML)

More from category: Any taxonomy

No comments
    Hello, !     Log In . Register