The edit_term_link() WordPress PHP function displays or retrieves the edit term link with formatting.
Usage
Here’s an example of how you could use the edit_term_link() function:
$term = get_term_by('slug', 'uncategorized', 'category'); edit_term_link(__('Edit', 'textdomain'), '<span class="edit-term">', '</span>', $term);
In this example, we first get the term object for the ‘uncategorized’ category. We then use the edit_term_link() function to output a link to edit that term, surrounded by <span>
tags with the class ‘edit-term’.
Parameters
- $link (string, optional): Anchor text. If empty, default is ‘Edit This’. Default: ”.
- $before (string, optional): Display before edit link. Default: ”.
- $after (string, optional): Display after edit link. Default: ”.
- $term (int|WP_Term|null, optional): Term ID or object. If null, the queried object will be inspected. Default: null.
- $display (bool, optional): Whether or not to echo the return. Default: true.
More Information
See WordPress Developer Resources: edit_term_link()
Examples
Basic Usage
This will output an ‘Edit This’ link for the ‘uncategorized’ category, surrounded by <span>
tags.
$term = get_term_by('slug', 'uncategorized', 'category'); edit_term_link('', '<span>', '</span>', $term);
Custom Link Text
This will output a ‘Modify This Category’ link for the ‘uncategorized’ category.
$term = get_term_by('slug', 'uncategorized', 'category'); edit_term_link('Modify This Category', '', '', $term);
No Auto Echo
This will return the ‘Edit This’ link for the ‘uncategorized’ category without echoing it.
$term = get_term_by('slug', 'uncategorized', 'category'); edit_term_link('', '', '', $term, false);
With Before and After Text
This will output ‘Start’ and ‘End’ before and after the ‘Edit This’ link respectively for the ‘uncategorized’ category.
$term = get_term_by('slug', 'uncategorized', 'category'); edit_term_link('Edit This', 'Start', 'End', $term);
Using Term ID
This will output an ‘Edit This’ link for the term with ID 123.
edit_term_link('', '', '', 123);