Home / functions.php / Add post class to posts with read more link
  • How to Add post class to posts with read more link

    add-post-class-to-posts-with-read-more-link

    Adding this snippet to the functions.php of your wordpress theme will add a post class to posts that contain a read more link.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    function mfields_add_more_to_post_class( $classes ) {
        global $post;
        if ( ( is_archive() || is_home() ) && false !== strpos( $post->post_content, '<!--more-->' ) && ! in_array( 'more', $classes ) ) {
            $classes[] = 'more';
        }
        return $classes;
    }
    add_filter( 'post_class', 'mfields_add_more_to_post_class' );
    

    ( WordPress codex functions, hooks, in this snippet. )

    home, post_class, add_filter, is_archive, is_home,