• Resolved yrzhn

    (@yrzhn)


    Hello!

    The text in the excerpt of the event description in the list page gets cut off after 30 words and I would like to add some CTA button like “read more” or “…more” right after it or below maybe, because it is odd if the excerpt ends in the middle of a sentence and/or with an article (“a”/”the”), for example and there’s no clear button to open the single event page, it is not very obvious. ??

    So far I only found the code to alter the number of the words that are shown in the excerpt which isn’t what I needed, but maybe it will help with a solution.

    // Changes the excerpt length for events to 100 words
    function custom_excerpt_length( $length ) {
    if( tribe_is_event() && is_archive() ) {
    return 100;
    }
    }
    add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );

    • This topic was modified 1 year, 6 months ago by yrzhn.
    • This topic was modified 1 year, 6 months ago by yrzhn.
    • This topic was modified 1 year, 6 months ago by yrzhn.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter yrzhn

    (@yrzhn)

    I managed to add the button right under the text by adding the following code I found here in the following file tribe/events/v2/list/event/description.php

    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Read more &raquo;</a>

    However, I still wonder whether I can implement it to appear on the same line with the excerpt text or maybe add something like “[…]” in the end without the link if it’s impossible to add the link.

    • This reply was modified 1 year, 6 months ago by yrzhn.
    • This reply was modified 1 year, 6 months ago by yrzhn.
    Thread Starter yrzhn

    (@yrzhn)

    Alternatively, maybe, it would be cool if the excerpt ended by the second or third sentence and not by a certain amount of words. Don’t know how to make it possible.

    Thread Starter yrzhn

    (@yrzhn)

    Found this and understood that I just need to use manual excerpt field in such cases, however, if it’s possible to put “read more” in the same line, that would be superb. ??

    https://theeventscalendar.com/blog/tips/the-trouble-with-excerpts/

    Jean A

    (@jeanabarquez)

    Hi @yrzhn,

    Thank you for reaching out to us!

    To modify the event excerpt so that it only shows the first two sentences and includes a “Read more” link, you can add the following snippet to your theme’s functions.php file:

    function custom_event_excerpt( $excerpt, $post ) {
        if ( tribe_is_event( $post ) ) {
            // Get the first two sentences of the excerpt
            $sentences = preg_split( '/(\.|\?|\!)(\s)/', $excerpt, 3, PREG_SPLIT_DELIM_CAPTURE );
    		// Concatenate the first 5 elements of an array, including the delimiters. (2 sentences)
    		$excerpt = '';
            for ( $i = 0; $i < 5; $i++ ) {
        		if ( isset( $sentences[ $i ] ) ) {
            	$excerpt .= $sentences[ $i ];
        		}
    		}
            
            // Add "Read more" link
            $link = tribe_get_event_link( $post );
            $excerpt .= '<a href="' . esc_url( $link ) . '"> ...Read more</a>';
        }
        
        return $excerpt;
    }
    add_filter( 'tribe_events_get_the_excerpt', 'custom_event_excerpt', 10, 2 );

    Do test it out on a staging site and let us know if that works for you.

    Kind regards,

    Jean

    Thread Starter yrzhn

    (@yrzhn)

    I couldn’t proceed with the code execution of the first part, it wouldn’t let me save the functions.php file but as I said, it works for me with manual excerpts, also it added the “Read More” button under the description, I am fine with that.

    That is probably a better way to have access to it from functions.php, than from description.php (takes a long while to locate the file), so it can be easily edited later on if needed. ??

    Also visitors will know that the button has its place below the description, rather than in the end of the text which will vary from one excerpt to the other…

    So thank you very much for the help. I will mark is as resolved.

    Hello,

    I just wanted to add that since the 6.2.1 update this bit of code appears to break the calendar layout if you click through month by month. Might be worth checking your calendar. I had this problem and it took me a while to work out. When I first open the calendar in month view it’s absolutely fine, but when I cycle through to the next months a bunch of the day cells ended up stacking on top of each other.

    I narrowed it down to this ibt of code which seemed to be adding an extra ahref link after some of the events, but outside of the cells, causing the whole calendar layout to break. Once I remove the code everything worked perfectly again. Hoping there can be an updated fix for this soon as I’d like to get control of the excerpt back on the calendar month views.

    Thanks

    Hi there,

    I’d love to add this code to have a Read More link after my excerpts as well. I don’t see where to add it, though, as that file path mentioned above “tribe/events/v2/list/event/description.php” doesn’t seem to be the right one anymore. If someone can tell me where to add this or if there is another way to add a Read More link to each excerpt, I would really appreciate it. Thank you so much!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to add “read more” button to the excerpt?’ is closed to new replies.