• Hi Guys,

    I searched the web and the available plugins, but I couldn’t find anything that is easy understandable for a noob like me to do the following:

    I learned how to create a “Continue Reading” link and how to set a post excerpt to a certain length of words.
    But I would like to get my “Continue Reading” link, if the following is set:
    1. If the post has more words than 45, then show the excerpt link. That is easy so far.
    2. If the post has less than 45 words and a picture/gallery is included, then set the “Continue Reading” link right after the text. That is not easy for me. How would the code look like for this?

    Many thanks for your help in advance.
    Kind regards.

Viewing 1 replies (of 1 total)
  • Thread Starter snowbeachking

    (@snowbeachking)

    I did some deeper research and came up with the following. I know that it won’t work, but some parts work as standalone, but I am not able to bring everything together. Maybe somebody can help to point me into the right direction?

    function individual_excerpt_more( $more ) {
    if {
        function word_count() {
            $content = get_post_field( 'post_content', $post->ID );
            $word_count = str_word_count( strip_tags( $content ) );
            return $word_count; <45 // (less than 45 words)
            }
        && $content = $post->post_content;
        if( has_shortcode( $content, 'gallery', 'video' ) ) {
        // The content has a [gallery] & [video] short code, so this check returned true.
        }
        return '&hellip; <ins><a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read more</a></ins>';
        }
    else {
        function theme_excerpt_length( $length ) {
            return 45;
        }
        add_filter( 'excerpt_length', ’theme_excerpt_length' );
    }
    add_filter( 'excerpt_more', 'individual_excerpt_more' );
Viewing 1 replies (of 1 total)
  • The topic ‘How to customize the excerpt’ is closed to new replies.