Make WordPress Core

Opened 8 years ago

Closed 5 years ago

Last modified 3 years ago

#23559 closed enhancement (wontfix)

Sticky single post page doesn't have .sticky class

Reported by: sgr33n Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: Posts, Post Types Keywords: 2nd-opinion
Focuses: template Cc:


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 (11)

#1 @sgr33n
8 years ago

  • Component changed from Themes to Template

#2 @SergeyBiryukov
8 years ago

  • Version changed from 3.5.1 to 2.7

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

#3 @sgr33n
8 years ago

Replied on that Ticket,

#4 @sgr33n
8 years ago


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

#5 @SergeyBiryukov
8 years 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 );

#6 follow-up: @sgr33n
8 years ago

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.

#7 @goto10
7 years ago

  • Cc dromsey@… added

#8 @nacin
7 years ago

  • Component changed from Template to Posts, Post Types
  • Focuses template added

#9 in reply to: ↑ 6 @obenland
6 years ago

Replying to sgr33n:

why this choice to exclude is_single().

Sticky posts are meant as a way to bump the priority of a specific post, regardless of the date it was published and its place in the timeline. Since it only has to be distinguished when displayed among other posts, there is no immediate need for that information on single where it is the only post displayed.

#10 @wonderboymusic
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I agree with obenland

This ticket was mentioned in Slack in #core by sergey. View the logs.

3 years ago

Note: See TracTickets for help on using tickets.