Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active December 29, 2015 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/420fd8b923c507ae18f2 to your computer and use it in GitHub Desktop.
Save tommcfarlin/420fd8b923c507ae18f2 to your computer and use it in GitHub Desktop.
An example function for how to add a class to a WordPress post to indicate if the given post has a `more` tag or not.
<?php
/**
* Adds a custom class to all posts that do not have a more tag embedded in their content.
* This makes for easier styling of the elements on archive pages.
*
* @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.
* @since 1.0.0
*/
function example_add_post_class_for_more_link( $classes ) {
global $post;
// If the more tag is not found in the post content, then add a class to signify it
if ( FALSE === strpos( $post->post_content, '<!--more-->' ) ) {
array_push( $classes, 'has-no-more-link' );
} // and if
return $classes;
} // end example_add_post_class_for_more_link
add_filter( 'post_class', 'example_add_post_class_for_more_link' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment