I need to apply a class to the post archive links that are output by WordPress’ get_archive_links function. I can accomplish this by modifying /wp-includes/general-template.php (line 842), from this:
$link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
to this:
$link_html = "\t<li>$before<a class='hello' href='$url' title='$title_text'>$text</a>$after</li>\n";
I’m pretty sure I need to add some sort of filter in my theme’s functions.php to accomplish this the smart way, without modifying a core file, I just don’t know how. Any guidance would be awesome.
EDIT: Here is the entire, unmodified function from general-template.php:
function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
$text = wptexturize($text);
$title_text = esc_attr($text);
$url = esc_url($url);
if ('link' == $format)
$link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n";
elseif ('option' == $format)
$link_html = "\t<option value='$url'>$before $text $after</option>\n";
elseif ('html' == $format)
$link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
else // custom
$link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
$link_html = apply_filters( 'get_archives_link', $link_html );
return $link_html;
}
So I figured out how to do this, thanks to this page.
Just throw this in
functions.php:Then call the new function wherever you’d like:
The example is obviously showing how to add a nofollow rel tag, but you can easily modify it to add a link class or anything else.