Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#28776 closed defect (bug) (invalid)

post_class should always return additional classes

Reported by: armymanch's profile armyman.ch Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: template Cc:

Description

When using post_class with a page that has no post (i.e. 404 page), custom classes passed to the function aren't set. Even if a post doesn't exist, at least the passed classes should be added to the class tag.

Change History (6)

#1 @obenland
11 years ago

  • Focuses template added

Thanks for bringing it up armyman.ch!
Could you provide a little more detail as to what is currently not working for you?

Looking at a 404 page in Twenty Fourteen, all custom classes do show up:

error404 logged-in admin-bar no-customize-support custom-background mp6 typekit-enabled group-blog masthead-fixed footer-widgets theme-menu-maximized highlander-enabled highlander-light custom-colors

#2 @armyman.ch
11 years ago

The body_class function works fine, it's the post_class function I'm talking about.
In /wp-includes/post-template.php, the function get_post_class returns an empty array if no post is found.
I would think that the correct behaviour would be to return an array of classes passed to the function.

#3 @obenland
11 years ago

Post classes are usually post-specific. When there is no post, these classes should not apply.
May I ask what your specific use case looks like?

#4 @obenland
11 years ago

  • Version changed from trunk to 2.9

For future reference, the current behavior was introduced in r12208.

#5 @armyman.ch
11 years ago

Basically, I was using the post_class function in all my theme templates, also 404.php. Then I noticed that the classes weren't being picked up by the function, which I thought might be a mistake. But as you have shown, it's intended behaviour. In that case, I will modify my 404.php and set the class tag directly.

Thanks for the reference, now I know that it's on purpose.

#6 @obenland
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 2.9 deleted
Note: See TracTickets for help on using tickets.