Using WordPress ‘post_column_taxonomy_links’ PHP filter

The post_column_taxonomy_links filter allows you to modify the links displayed in the taxonomy column of the WordPress admin’s edit.php page.

Usage

add_filter('post_column_taxonomy_links', 'your_custom_function', 10, 3);

function your_custom_function($term_links, $taxonomy, $terms) {
    // your custom code here

    return $term_links;
}

Parameters

  • $term_links (string[]): Array of term editing links.
  • $taxonomy (string): Taxonomy name.
  • $terms (WP_Term[]): Array of term objects appearing in the post row.

Examples

add_filter('post_column_taxonomy_links', 'add_custom_link_to_terms', 10, 3);

function add_custom_link_to_terms($term_links, $taxonomy, $terms) {
    foreach ($terms as $term) {
        $term_links[] = '<a href="' . esc_url('https://example.com/' . $term->slug) . '">Custom Link</a>';
    }

    return $term_links;
}

This code adds a custom link to each term in the taxonomy column, pointing to “https://example.com/term_slug“.

add_filter('post_column_taxonomy_links', 'remove_term_editing_links', 10, 3);

function remove_term_editing_links($term_links, $taxonomy, $terms) {
    return array();
}

This code removes all term editing links from the taxonomy column in edit.php.

add_filter('post_column_taxonomy_links', 'add_custom_class_to_term_links', 10, 3);

function add_custom_class_to_term_links($term_links, $taxonomy, $terms) {
    foreach ($term_links as &$link) {
        $link = str_replace('<a ', '<a class="custom-class" ', $link);
    }

    return $term_links;
}

This code adds a custom CSS class to each term editing link in the taxonomy column.

add_filter('post_column_taxonomy_links', 'change_link_target_to_new_tab', 10, 3);

function change_link_target_to_new_tab($term_links, $taxonomy, $terms) {
    foreach ($term_links as &$link) {
        $link = str_replace('<a ', '<a target="_blank" ', $link);
    }

    return $term_links;
}

This code changes the term editing links to open in a new tab when clicked.

add_filter('post_column_taxonomy_links', 'hide_term_links_for_specific_taxonomy', 10, 3);

function hide_term_links_for_specific_taxonomy($term_links, $taxonomy, $terms) {
    if ($taxonomy === 'custom_taxonomy') {
        return array();
    }

    return $term_links;
}

This code hides term editing links only for the ‘custom_taxonomy’. All other taxonomies will display their links as usual.