edit_term_link

函数
edit_term_link ( $link = '', $before = '', $after = '', $term = null, $echo = true )
参数
  • (string) $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty.
    Required:
    Default: (empty)
  • (string) $before Optional. Display before edit link. Default empty.
    Required:
    Default: (empty)
  • (string) $after Optional. Display after edit link. Default empty.
    Required:
    Default: (empty)
  • (int|WP_Term|null) $term Optional. Term ID or object. If null, the queried object will be inspected. Default null.
    Required:
    Default: null
  • (bool) $echo Optional. Whether or not to echo the return. Default true.
    Required:
    Default: true
返回值
  • (string|void) HTML content.
定义位置
相关方法
get_term_linkget_edit_term_linkedit_tag_linkedit_post_linkedit_link
引入
3.1.0
弃用
-

edit_term_link: 这个函数生成一个链接,用于在WordPress管理面板中编辑一个指定的术语,例如一个类别或标签。

显示或检索带有格式化的编辑术语链接。

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

常见问题

FAQs
查看更多 >