Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:11:02+00:00 2026-06-01T12:11:02+00:00

I need to apply a class to the post archive links that are output

  • 0

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;

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:11:04+00:00Added an answer on June 1, 2026 at 12:11 pm

    So I figured out how to do this, thanks to this page.

    Just throw this in functions.php:

    // Filter to add nofollow attribute
    function nofollow_archives($link_html) {
    return str_replace('<a href=', '<a rel="nofollow" href=',  $link_html);
    }
    

    Then call the new function wherever you’d like:

    <?php add_filter('get_archives_link', 'nofollow_archives'); ?>
    <?php wp_get_archives('type=monthly'); ?>
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to apply a class to the <li> tag that encloses an anchor
I need to apply validation on input time intervals that are taken in as
I need to apply a css class to invalid controls on a web form.
I need to display 4 li elements in a row, then apply a class=last
I need to apply CSS to a specific class and id of an element
I need to apply a custom style to my datepicker but can't work out
I need to apply a style to an element if a specific class is
WordPress spits posts in this format: <h2>Some header</h> <p>First paragraph of the post</p> <p>Second
I need to apply this script to work the same way for two other
Given a DIV with this general structure (class=post, from an extracted message board post)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.