Opened 3 months ago

Last modified 3 months ago

#23559 new enhancement

Sticky single post page doesn't have .sticky class

Reported by: sgr33n 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)

  • Component changed from Themes to Template
  • Version changed from 3.5.1 to 2.7

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

Replied on that Ticket,
Thanks!

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

  • 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 );

Thanks for your workaround Sergey... anyway my ticket was for ask why this choice to exclude is_single(). Maybe the decision was taken in the past for something now outdated, so it could make sense to activate it again.

Note: See TracTickets for help on using tickets.