Home WordPress Links Functions edit_tag_link() WordPress edit_tag_link() Function Definition In WordPress, edit_tag_link() prints an edit link for a post tag. The link opens that tag in the admin area.
Use it in a tag archive template, next to the tag title. If you do not pass a tag, WordPress uses the tag that is being shown. The link appears only for users who can edit tags.
Syntax Call it on a tag archive page, or pass a tag.
<?php edit_tag_link( 'Edit tag' ); ?> Call What it does edit_tag_link( 'Edit tag' )Print an edit link for the tag being viewed. edit_tag_link( 'Edit', '<p>', '</p>' )Wrap the link in a paragraph. edit_tag_link( 'Edit', '', '', 7 )Print the edit link for the tag with ID 7.
It prints the link. It only works for tags (the post_tag taxonomy).
Full declaration edit_tag_link( string $link = '', string $before = '', string $after = '', int|WP_Term $tag = null ): void Parameters Parameter Description $linkstring. The link text. If empty, WordPress uses its default text (Edit This). $beforestring. HTML printed before the link. $afterstring. HTML printed after the link. $tagint|WP_Term. A tag ID or a term object. Default is null, which means the current tag.
Return Value Return Value Description void Nothing is returned. The link is printed only when the user can edit the tag.
WordPress Examples Three short examples. Each one shows the code and what it prints or does.
1. Add an edit link to a tag archive 2. Wrap the link with before and after 3. Pass a tag object Example 1 — Add an edit link to a tag archive Show the tag name, then the edit link for admins.
<?php
// tag.php
single_tag_title( '<h1>', '</h1>' );
edit_tag_link( 'Edit tag' ); <h1>News</h1>
<a href="https://example.com/wp-admin/term.php?taxonomy=post_tag&tag_ID=7&post_type=post" class="post-edit-link">Edit tag</a> How It Works single_tag_title() prints the tag name.edit_tag_link() finds the current tag by itself.Only a user who can edit tags sees the link. Example 2 — Wrap the link with before and after Add HTML around the link without printing empty markup for visitors.
<?php
edit_tag_link( 'Edit', '<p class="tag-tools">', '</p>' ); <p class="tag-tools"><a href="https://example.com/wp-admin/term.php?taxonomy=post_tag&tag_ID=7&post_type=post" class="post-edit-link">Edit</a></p> How It Works The text is Edit. The paragraph prints only when the link prints. Visitors get clean HTML. Example 3 — Pass a tag object Use a tag you looked up yourself, even outside a tag archive.
<?php
$tag = get_term_by( 'slug', 'tutorials', 'post_tag' );
if ( $tag ) {
edit_tag_link( 'Edit the Tutorials tag', '', '', $tag );
} <a href="https://example.com/wp-admin/term.php?taxonomy=post_tag&tag_ID=12&post_type=post" class="post-edit-link">Edit the Tutorials tag</a> How It Works get_term_by() finds the tag with the slug tutorials.We check that the tag exists. edit_tag_link() uses that tag instead of the current one.Frequently Asked Questions What does edit_tag_link() do? It prints a link to the admin screen where a post tag can be edited. Only users who can edit tags see it.
Does it work for categories? No. It is for tags only. For categories and other taxonomies use edit_term_link().
Where should I use it? In tag.php or any template that shows a tag archive. You can also use it elsewhere if you pass a tag.
Does it return the URL? No. It prints a full link. To get only the URL use get_edit_tag_link().
Why is nothing printed? The user may not be logged in, may lack permission, or the tag could not be found.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
14 people found this page helpful
Helpful Share Copy link Suggestion