Add Class To 1st Post On First Page of Paginated Archive Page

This PHP code enables you to add a custom class to the first post on any archive page loop.

The code, which works in any theme, only adds your custom class to the 1st post on the 1st page only so.

Video Demo

This means that the 2nd and subsequent pages of your paginated archive will remain uneffected andthe classonly added to one post in the entire loop.

You can use the code in:

  1. A template file, using the WordPress Template Hierachy
  2. Your functions file with conditional tag

On top of this, you can use replicate the code to add custom classes to 2nd, 3rd and other posts in any archive loop.

Here’s the code for logged in members:

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.