Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.