
term_links-{$taxonomy}
The term_links-{$taxonomy} hook in WordPress is used to filter the links for terms within a specified taxonomy.
The term_links-{$taxonomy}
hook in WordPress is used to filter the links for terms within a specified taxonomy. This hook allows developers to modify how term links are displayed, offering flexibility in customizing the output.
The hook name includes a dynamic portion, $taxonomy
, which represents the specific taxonomy slug. For example, it can be term_links-category
for categories, or term_links-post_tag
for tags. (WordPress Developer Resources).
Possible hook names include:
term_links-category
term_links-post_tag
term_links-post_format
Parameters:
$links
string[] – An array of term links.
When using this hook, ensure your modifications align with the site’s navigation and taxonomy structure. Testing changes in a development environment before applying them to a live site is recommended to avoid conflicts or issues
function limit_to_two_tags( $links ) {
return array_slice( $links, 0, 2, true );
}
add_filter('term_links-post_tag', 'limit_to_two_tags');
This code can be added to your theme’s functions.php
file or a custom plugin. It ensures that only the first two tags associated with a post are displayed, helping to maintain a clean and manageable tag list on the frontend.