Not exactly what you asked for, but given that classes are primarily used for styling, might you consider using CSS pseudo-class “:last-child” instead of PHP code?
Here’s some information on how to style using :last-child
Related Posts:
- Style custom columns in admin panels (especially to adjust column cell widths)
- How to add a CSS class to every image in a Custom Post Type
- CSS for Custom Post Types
- Is it possible to insert text into an html tag using functions.php?
- How do you use JavaScript to detect the homepage
- Add the current menu item CSS class to a custom page type archive in WordPress menu
- different template for first and second level custom post page
- Change post featured image on hover
- Custom post type and body_class: Remove “blog” class
- Customize my custom taxonomy table in Admin panel
- How to Create Columns with WordPress and CPTUI display page ?
- Add custom CSS class to custom post type
- Give each post type label a different color?
- Displaying custom post types as a gallery
- Trying to add a class to post links
- One Site. One Theme. Multiple Stylesheets without plugins?
- Posts are not rendering perfectly [closed]
- Questions regarding add_meta_box()
- Multiple Stylesheets For Post and post type?
- Use conditionals with wp_enqueue_style to attach stylesheet according to post type displayed
- DIVI Theme customizer changes not applied on existing pages and designs are not shown on the front
- Custom post type not pulling CSS
- Is it possible to link an external stylesheet, exclusively within a specific single post template?
- Change Background Color For CPT Template
- Can’t open Custom Post Types Link in navigation
- Multiple search template with separate stylesheets
- Multiple Block Quotes without using HTML
- How to insert post into a page?
- Woocommerce product page is not showing custom css [closed]
- WordPress custom post type odd and even styling [duplicate]
- How do I target a links only in a custom post type and only in the p tag?
- Add a background image into a post [closed]
- how to display custom taxonomies in front page
- New post status for custom post type
- Adding Custom Post Type Counts to the Dashboard
- How can I filter posts by post_parent in the admin?
- Get Custom Taxonomy ID within loop
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- Using Templates with Custom Post Type UI
- WordPress Custom Post Type Admin Page really slow
- How to setup a Custom Taxonomy Term template
- Creating a gallery of featured images from custom post type
- Retrieve a specific field from taxonomy term through advanced custom fields [closed]
- Custom post type: No posts found even if counter has a count
- Custom field default value with counter
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Warning when attempting to edit/add custom post type
- How does register_post_type know how and which function to use from the add_action function?
- WordPress Create Post from front-end
- List Post Title by Last Word Then Second Last
- Am I using the flush_rewrite_rules function in the right place?
- Query custom post type with tags
- Custom post types team data
- WordPress permalink / slug with numbers in the middle of the post name shows the broken page
- Display post as term id
- WordPress custom post type permalink rewrite shows page not found
- Create a Dropdown from Custom Post Type
- Custom post type conditional in loop
- Showing specific post in order of array wp_query
- Why cant I add a custom post type to a custom taxonomy?
- the_post_thumbnail call removing li in code
- How to display custom post type tags?
- Featured image size in column
- Submitting Custom Post Types with custom fields from Front-end form
- Custom WP_Query always respond with 200 status even when no entry
- Page Template Dropdown For Custom Post Types
- Get_the_terms restrict output
- Can I query posts by taxonomy conditionally based on post type?
- Include custom post type custom taxonomies in Categories widget
- Break up posts per page in two sections
- post_content is stripping HTML when adding a new post? [closed]
- Querying a custom post type, but not show duplicates
- Can’t replace the default sidebar with a custom sidebar on Custom Post Type in Genesis
- Dynamic category name in query post
- Two queries – one with checkbox ticked, one without – comparing meta_query
- Ignores post_type when no results
- Can I decide what categories show on my posts page?
- Link custom post type to users membership
- WordPress – display relationship between blog posts and custom posts
- Load info from customposttype into template page
- Multiple Loops In Tabs Only Displaying First Loop
- WP_Query to display number of custom post type filtered (order by) taxonomy
- Display post in sequence from different custom post_type
- Sort loop by custom field from different post type
- Custom post meta box as a sub form
- How to create groups like that in buddypress?
- Custom meta box data not saving
- Custom post type rewrite and wp_pagenavi interfering with each other
- Include template if a post is a single product
- Custom meta-box for all custom post types
- Retrieve a specific category of posts when using a custom post type
- General question about Parent and Child Post type relationships
- WordPress Load more posts by ajax not working
- Multiple while loops not functioning [closed]
- Listing all custom post types using a specific term on the said term’s template page, in groups
- How to write an if statement which reads: ‘if is this custom post type or a child of it do the following’?
- taxonomies or categories w/custom post
- Require Custom Taxonomy for Custom Type
- Get post from custom post type that title is like custom string [closed]
- Post object GUID adding http:/