Opened 3 months ago
Last modified 3 months ago
#23559 new enhancement
Sticky single post page doesn't have .sticky class
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Template | Version: | 2.7 |
| Severity: | normal | Keywords: | 2nd-opinion |
| Cc: |
Description
As explained in summary, it's impossible to style a single page for a sticky post without modifying content.php, why this? it's a behavior wanted.
wp-includes\post-template.php, line 344:
// sticky for Sticky Posts if ( is_sticky($post->ID) && '''is_home()''' && !is_paged() ) $classes[] = 'sticky';
Thanks :)
Change History (6)
comment:2
SergeyBiryukov — 3 months ago
- Version changed from 3.5.1 to 2.7
So...
Why this? It should be good to have the same class on the single page. You can even overwrite the default style via css by using .single .sticky
comment:5
SergeyBiryukov — 3 months ago
- Keywords 2nd-opinion added
A workaround:
function sticky_class_for_single_post_23559( $classes, $class, $post_id ) {
if ( ! in_array( 'sticky', $classes ) && is_sticky( $post_id ) && ! is_paged() )
$classes[] = 'sticky';
return $classes;
}
add_filter( 'post_class', 'sticky_class_for_single_post_23559', 10, 3 );
Note: See
TracTickets for help on using
tickets.

is_home() was added in [8847] (for #7712).