2026 Executive BenchmarkMid-Market Enterprise Modernization: How leaders across unify Commerce, Odoo ERP & AI in 90 days.
WORDPRESS

Add Custom Class To Last Post In A Loop WordPress:

Put this below code in Function.php File and save. return $classes; } add_filter('post_class', 'last_post_class'); ?> After this you display your class name in your last Post.

Akshar Group Technologies
Dec 25, 2020
1 min read
Verified Source

Put this below code in Function.php File and save.

php
<?php
functionlast_post_class($classes){
global $wp_query;
if(($wp_query->current_post+1) == $wp_query->post_count) $classes[] = 'Your Class Name';
return $classes;
}
add_filter('post_class', 'last_post_class');
?>
After this you display your class name in your last Post.
Share this playbook
LET'S BUILD WHAT'S NEXT

What's Holding Your Business Back?

Tell us where you want to go, what's getting in the way, and we'll help you figure out the technology to get there.

No sales pitch. Confidential strategic advisory.