I’m looking for how to get a class in the wp_get_archives functions to get the current month (when we are in a month archive) just like when we call wp_list_categories, the current category has a “.current-cat” selector for CSS or when we call wp_list_pages we have a ‘.current_page_item’ selector.
Leave a Reply
You must be logged in to post a comment.
Put the following function in your
functions.php
And then add the following line just before calling
wp_get_archives()
You might also want to remove the filter after calling
wp_get_archives()
so that it doesn’t mess with otherwp_get_archives()
orget_archives_link()
function calls.This function was created with the great help of Joshua Abenazer. Thanks! Basically, if is a monthly archive, go and get the current month watched, and add a class on the li. Worked great.
As of WordPress 5.3,
<a>
elements generated by wp_get_archives (etc) for links to the current page have the attributearia-current="page"
added to them. If you just want to style the current page link differently, you can now target this with CSS, assuming you are happy for the styles to all be on the<a>
:â¦or even just: