Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin

tommcfarlin/post-no-more-tag.php Secret

Last active Dec 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.