The announcement excerpts get generated using the built-in WordPress function the_excerpt();
. When you setup an announcement, and the excerpt isn’t long enough to warrant a read more link – it doesn’t get generated and therefore requires that your users click on the circle and icon in the middle of the timeline to view the post.
If you want the ‘Read More’ links to appear on all of the announcements regardless of the length of the announcement content – you’ll need to add two snippets to your themes functions.php file.
The two functions, when working together, will hide the default generated ‘…read more’ links and generate a custom ‘Read More’ link regardless of the length of the content.
Hide the Default ‘…Read More’ Links
The first function, as mentioned above, will hide the default generated ‘Read More’ links, and the three ellipses before it. This filter can be used to alter the read more link, or simply remove it altogether – which is what we’ll be doing.
/** * Remove the default Timeline Express read more links * @param string $read_more Default HTML markup for the read more link. * @param integer $post_id Post ID of the current announcement iteration. * @return null */ function custom_timeline_express_readmore( $read_more, $post_id ) { return ''; } add_filter( 'timeline_express_read_more_link', 'custom_timeline_express_readmore', 10, 2 );
As mentioned above, you’ll want to add the above snippet into the bottom of your themes functions.php file. Once you add it to your functions.php, you should no longer be seeing the default ‘Read More’ links, and preceding ellipses.
Once you’ve removed the default ‘Read More’ links from the plugin – using the filter above, you can proceed to generating your own custom Read More links.
Generate Custom Read More Links
Now we can hook into the included action hook `timeline-express-after-excerpt`, to generate a custom read more link directly after the excerpts of our announcements.
Again, you’ll want to enter the following snippet into the bottom of your themes functions.php file. You can add it directly below the snippet from above.
/** * Generate a new custom 'Read More' link * @return string HTML markup for the new read more link. */ function generate_custom_read_more_link() { global $post; echo wp_kses_post( '<a href="' . get_the_permalink( $post->ID ) . '" class="custom-class">Read Me!</a>' ); } add_action( 'timeline-express-after-excerpt', 'generate_custom_read_more_link' );
Results
After you’ve added the above two snippets to your themes functions.php file, and saved it – you should now see a new link below the excerpt ‘Read Me!’, regardless of the length (even when there is no announcement content at all).
You can alter the link text, add additional classes or use a different element altogether by altering the generate_custom_read_more_link()
from above. Keep in mind, the location of this hook can be used to display additional elements such as share buttons.
For short posts where I don’t want to include a read more link, I checked to make sure that the excerpt is the same as the content.
function custom_timeline_express_readmore( $read_more, $post_id ) {
$post = get_post($post_id);
$excerpt = get_the_excerpt($post);
$post_content = get_post_field(‘post_content’, $post_id);
if($post_content == $excerpt){
return ”;
}
return $read_more;
}
add_filter( ‘timeline_express_read_more_link’, ‘custom_timeline_express_readmore’, 10, 2 );
Hi Jason,
Feel free to reach out to us via the contact form here on our site and we’ll be glad to help out. We’ll need to do some testing, but what you have looks like a good start. We can provide you with properly formatted code via an email better than we could here.
Thanks,
Evan
This doesn’t work!
We’re unsure of what is not working for you. If you are facing issues feel free to reach out to our support team using the contact button in the navigation.
Sorry, my bad, it works.
Though this doesn’t seem to be the case:
“When you setup an announcement, and the excerpt isn’t long enough to warrant a read more link – it doesn’t get generated, and therefore requires that your users click on the circle and icon in the middle of the timeline to view the post.”
I get Read more-links on everything, regardless of length. I’d like it to work as described here, and modify the text of the “Read more”. Is that possible?
Is there any anorher posibility to add a custom link? I would not like to manipulate php, I am a beginner.
Hi Lisa,
What are you attempting to do? Tweak the text of the read more links, tweak their appearance, remove them altogether?
There are a few ways you can customize the read more links. You can use a filter built into the plugin to update the URLs, the text, add any classes to aid in styling them a bit better etc. You can copy over the template file into your local theme, and add new HTML markup around any part of the announcement containers or remove the read more links from the files. You can use CSS to just hide the read more links at the bottom of the announcement containers.
I’d like the image to be a read more link. Is that possible?