-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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