Unlike the (WP standard) Custom Menu widget, the Recent Posts widget does not add the current_menu_item class when a post is selected (being displayed).

This seems like a major oversight, am I missing something? If not, does anyone know of a third party widget that lists the most recent posts and includes the current_menu_item class (or equivalent)? ...or perhaps some magical hack to achieve the result of adding a class to the active menu item?

1 Answer 1


The core Recent Posts Widget does not output any classes for the current post - probably because the Widget semantically is a list of posts, rather than a navigation menu, and therefore has no intended purpose to reflect current location.

That said, with a bit of CSS/jQuery trickery, you could target the current post by matching the current post's permalink and/or ID to the href and/or title attribute of the Recent Posts Widget list item link.

While the implementation itself is probably outside the scope of WPSE, the relevant code is here:

<?php  while ($r->have_posts()) : $r->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
<?php endwhile; ?>

Use jQuery to match e.g. .widget li a[href=<?php get_permalink(); ?>], or something along those lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.