• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Web
  • Creative
  • Mobile
  • IT
  • Code
  • CMS
  • Podcast
  • Memes
  • Resources
  • Newsletter
  • About

ChurchMag

The #1 Resource for Church Technology Creativity & New Thinking

Web Hosting

ChurchMag / CMS / How-To Add a Class to the First Post in Your WordPress Loop

How-To Add a Class to the First Post in Your WordPress Loop

How-To Add a Class to the First Post in Your WordPress Loop

September 19, 2012
by Eric Dye

If you want to add some … uh … excuse the pun … class to the first post listed on your WordPress blog, here’s the solution. Maybe you hadn’t even thought of such a thing, but now that I’ve mentioned it, your creative mind has been flipped-on. 😉

As with many WordPress mods, all you’ll have to do is add your snippet into your functions.php.

How-To Add Some Class

Drop this into your functions.php or functionality plugin:

add_filter( 'post_class', 'wps_first_post_class' );
function wps_first_post_class( $classes ) {
global $wp_query;
if( 0 == $wp_query->current_post )
$classes[] = 'first';
return $classes;
}

This particular example ads the class name “first,” but you can name it to whatever you like.

With this in place, your WordPress theme will add the class “first” to the first post in your WordPress Loop.

[via WP Snipp]

Eric Dye

Support Lead at Valet, and Proprietor of DYECASTING. Human by day, gamer at night, lover of coffee, and all things spicy.

Category: CMS, Code, PHP, WordPress

Level up your inbox.

Free resources, top posts, and more!

Reader Interactions

There are 2 comments already... Come join us!

  1. Craig Allen says

    September 19, 2012

    This is great, I can already think of a few interesting ways to use this. Thanks!

    Reply
    • Eric Dye says

      September 20, 2012

      Sweet!

      Reply

Speak your mind... Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



‹ Previous

[Free] Social Media Ministry Strategy

Next ›

Focused Blogging: Standing Out from the Crowd

Footer

Web Hosting

About

About
Contact
Advertise
Write for Us!
ChurchMag Minecraft Server

We #HEART

Powered by

Member of the ChurchMag Family

ChurchMag Podcast

Tired of Video Conference Calls

Are You Tired of Video Conference Calls? [Podcast #321]

Pick your favorite ways to connect.

Comment Policy / Privacy Policy / Archive / Log in

© 2021 ChurchMag