I’m working on a website that uses a static front page. It also shows the single most recent blog post. This was achieved by creating a page and using a custom page template.
Sometimes, the blog post is too long, so I want to use the_excerpt to automatically shorten it without the need for a more tag.
So far so good. But, the_excerpt doesn’t actually create a “read more” link. This is a pretty common problem, so I added:
<?php
function new_excerpt_more($more) {
global $post;
return '... <a href="'. get_permalink($post->ID) . '">continue reading</a>.';
}
add_filter('excerpt_more', 'new_excerpt_more');
?>
to my functions.php file.
I’ve actually used this code without issue on another site, but for whatever reason, it’s not working in this case. My initial guess was that it was because it’s being called on a static page.
The website is http://stuandjessproductions.com. The theme is Central by QODE, and I’m using a custom child theme.
EDIT
Adding code from the template page, as per request. This isn’t the whole page, but rather just the relevant bit for the news post:
<?php $query = "showposts=1&orderby='date'"; query_posts($query);?>
<?php if(have_posts()) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink();?>"><?php the_post_thumbnail('home'); ?></a>
<div class="overlay">Latest News</div>
<h4><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h4>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php endif; ?>
On the post edit page, if you fill Excerpt box with any text,
the_excerpt()
function doesn’t addread more link
or...
at the end of the short description at frontend. Read more link is only included if Excerpt is set empty. This is not a bug, it’s a default behavior.The solution is to avoid the
excerpt_more
filter to returnread more link
, and use thethe_excerpt
hook to add read more link.Above code could go to your themes functions.php file.