Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created December 6, 2013 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/95fcd25050e860049100 to your computer and use it in GitHub Desktop.
Save tommcfarlin/95fcd25050e860049100 to your computer and use it in GitHub Desktop.
[WordPress] If the given post is a single post, then add a class to this post.
<?php
/**
* If the given post is a single post, then add a class to this post.
*
* @param array $classes The array of classes being rendered on a single post element.
* @return array $classes The array of classes being rendered on a single post element.
* @package example
* @since 1.0.0
*/
function example_add_post_class_to_single_post( $classes ) {
if ( is_single() ) {
array_push( $classes, 'single-post' );
} // end if
return $classes;
}
add_filter( 'post_class', 'example_add_post_class_to_single_post' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment