Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Wordpress' Excerpt with a "more" link?

Tags:

wordpress

Wordpress' documentation suggests adding the following to functions.php to enable what I want to do:

function new_excerpt_more($post) {
    return '<a href="'. get_permalink($post->ID) . '">' . 'Read the Rest...' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

As per: http://codex.wordpress.org/Function_Reference/the_excerpt

But when I add this to functions.php, and I attempt to use it, I don't see the more link. Here is how I try to use it:

the_excerpt(__('(more...)'));

I've also tried:

the_excerpt();

Update: I've tried the following, but it either returns an error (if no arguments), or it doesn't display any excerpt or anything (if an argument):

function new_excerpt_more($excerpt) {
    $link = get_permalink();
    $title = the_title('','',false);
    $ahref = '<a href="'.$link.'" title="'.$title.'">more...</a>';
    return str_replace('[...]', $ahref, $excerpt);
}
add_filter('wp_trim_excerpt', 'new_excerpt_more');
like image 582
Matrym Avatar asked Jun 30 '10 19:06

Matrym


People also ask

How do I use read more tag in WordPress?

While creating a post in the Classic editor's Visual editor, place the cursor at the point where you wish for the preview to end and select the Insert Read More tag option from the toolbar displayed above the text. You can also move it with the left-mouse click and place it wherever you please.

How do I add a continue to read link in WordPress?

You can insert the WordPress "Read More Tag" where you'd like the "Continue Reading" or "Read More" button to appear (text will depend on which theme you're using). ADDING THE READ MORE TAG: When creating/editing a post, hover your cursor beneath the Gutenberg block where you want the "Read More Tag" to go.


1 Answers

function new_excerpt_more($output) {
    return $output . '<p><a href="'. get_permalink() . '">' . 'Read the Rest...' . '</a></p>';
}
add_filter('get_the_excerpt', 'new_excerpt_more');

Works with:

<?php the_excerpt(); ?>
like image 181
Matrym Avatar answered Sep 20 '22 22:09

Matrym