apply_filters( ‘get_archives_link’, string $link_html, string $url, string $text, string $format, string $before, string $after, bool $selected )

Filters the archive link content.

Parameters

$link_htmlstring
The archive HTML link content.
$urlstring
URL to archive.
$textstring
Archive text description.
$formatstring
Link format. Can be 'link', 'option', 'html', or custom.
$beforestring
Content to prepend to the description.
$afterstring
Content to append to the description.
$selectedbool
True if the current page is the selected archive.

Source

return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected );

Changelog

VersionDescription
5.2.0Added the $selected parameter.
4.5.0Added the $url, $text, $format, $before, and $after parameters.
2.6.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    You can use this filter to add current-archive class to element (as current-cat in wp_list_categories() function):

    function example_get_archives_link($link_html) {
        if (is_day() || is_month() || is_year()) {
            if (is_day()) {
                $data = get_the_time('Y/m/d');
            } elseif (is_month()) {
                $data = get_the_time('Y/m');
            } elseif (is_year()) {
                $data = get_the_time('Y');
            }
    
            // Link to archive page
            $link = home_url($data);
    
            // Check if the link is in string
            $strpos = strpos($link_html, $link);
    
            // Add class if link has been found
            if ($strpos !== false) {
                $link_html = str_replace('<li>', '<li class="current-archive">', $link_html);
            }
        }
    
        return $link_html;
    }
    add_filter("get_archives_link", "example_get_archives_link");

You must log in before being able to contribute a note or feedback.