Okay
  Public Ticket #1076368
Hide read more text and adjust excerpt length for blog posts?
Closed

Comments

  •  2
    Albin started the conversation

    Hi,

    I want to be able to manually adjust the length of the excerpt for my blog posts. 

    One way of doing that would be to use read more, but the read more does not show? Right now if I use the "readmore" for a blog post, the text  (mer…) comes up. Is it possible to make (mer…) hidden?

    /Albin

  •  1,558
    Laborator replied

    Hi Albin,

    Can you please share your site credentials here, because we need to login to your site and see this issue live. Your information is safe (private) in this thread.

    To include your credentials click Insert Credentials button in editor toolbar. (See how)

    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group

  •   Albin replied privately
  •  1,558
    Laborator replied

    Hi Albin,

    They're simply not working, tried them 3 times but unfortunately without any success.

    Can you please re-check them and come back here.

    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group

  •   Albin replied privately
  • [deleted] replied

    Hi Albin,

    I have added this code in functions.php:

    // Remove blog posts excerpt
    function blog_remove_excerpts( $excerpt) {
    global $post;

    if ( 'post' == $post->post_type ) {
    return '<a href="' . get_permalink( $post ) . '">Read more...</a>';
    }

    return $excerpt;
    }

    add_filter( 'get_the_excerpt', 'blog_remove_excerpts', 10 );

    And it removed the excerpt from posts, now it only shows  Read more as you suggested (you can change that text as well).

    I hope this works fine for you.

  •  2
    Albin replied

    Hi Arlind,

    I must have been very unclear with what I wanted and I'm sorry for that.

    I wanted to use the Read more tag as a way of manually choosing the excerpt length while not seeing the "Read me"-text.

    So basically what I want you to change is:  shorten the excerpt, but do not remove it.  I want the excerpt to be no longer than 100 words (2 lines).

    Hope it makes sense.

    Thanks for the fast support!

    /Albin

  • [deleted] replied

    Hi Albin

    Can you try this version please, i hope you like it. thank you.

    // Remove blog posts excerpt
    function blog_remove_excerpts( $excerpt) {
        
        return $excerpt;
    }
    add_filter( 'get_the_excerpt', 'blog_remove_excerpts', 10 );
    function new_excerpt_more( $more ) {
        return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'kalium') . '</a>';
    }
    add_filter( 'excerpt_more', 'new_excerpt_more' );
    function custom_excerpt_length( $length ) {
        return 20; //change this for word length 
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  •  2
    Albin replied

    Love it! Thank you!

    Keep rocking guys,

    Albin

  • [deleted] replied

    Glad to hear that.

    Thank you.