标记链接我要添加过滤器来修改在WP get_the_tag_list
生成的链接。它调用了get_the_term_list
添加过滤器添加类在WordPress
function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '') {
$terms = get_the_terms($id, $taxonomy);
if (is_wp_error($terms))
return $terms;
if (empty($terms))
return false;
$links = array();
foreach ($terms as $term) {
$link = get_term_link($term, $taxonomy);
if (is_wp_error($link)) {
return $link;
}
$links[] = '<a href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
}
我想补充class="tag"
,但我不知道如何写一个过滤器为我functions.php文件的目标只有$links[]
位该功能的。我可以排除旧的链接集并以某种方式添加我的修改过的链接集吗?
我想加入这样的事情,但我有它在某种程度上错误:
add_filter('get_the_term_list','replace_content');
function replace_content($links[])
{
$links[] = str_replace('<a href="', '<a class="tag" href="', $links[]);
return $links[];
}
你使用哪种版本的WordPress的?这仅仅是为了'标签'分类吗? – TeeDeJee
其版本4.3 – antonanton