Opened 4 years ago
Closed 4 years ago
#10395 closed enhancement (fixed)
wp_trim_excerpt() filterable [...] string
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.9 |
| Component: | Template | Version: | 2.8 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | r_a_m_i@…, ramiy |
Attachments (2)
Change History (10)
- Cc ramiy added
- Keywords has-patch excerpts wp_trim_excerpt excerpt_more added
i agree with you, but the filter the_content_more_link works only when using the_content() function. And all other techniques to change the more-tag (http://codex.wordpress.org/Customizing_the_Read_More) don't work when using the_excerpt() function.
- Component changed from General to Template
- Milestone changed from 2.8.2 to 2.9
comment:5
in reply to:
↑ 3
stewartKnapman — 4 years ago
Why not use php's preg_replace function?
With a little regexp you can find the '[...]' and replace it with what ever you like.
I just added this to my functions.php
eg:
function moreLink($content){
return preg_replace('/(\[...\])/','<small><a href="'.get_permalink().'">More ...</a></small>',$content);
}
add_filter('the_excerpt', 'moreLink');
I just added this to my functions.php eg:
Just note that that doesnt work as you expect. It'll also replace [ABC] with the more link..
Since you're not using a regular expression, you're better off using str_replace:
function moreLink($content){
return str_replace('[...]','<small><a href="'.get_permalink().'">More ...</a></small>',$content);
}
add_filter('the_excerpt', 'moreLink');
This is a very nice solution but it doe's not provide a general solutin to the real problem - The the_content_more_link filter does not work when using the_excerpt() function.
Besides, the solution must be in the wp core whitout using functions.php file.
Adding a new filter to wp_trim_excerpt() function is simpler to use and it workes the same as $excerpt_length filter.
// Changing excerpt length
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
// Changing excerpt more
function new_excerpt_more($more) {
return '.....';
}
add_filter('excerpt_more', 'new_excerpt_more');
bouth filters are in wp_trim_excerpt() function.
comment:8
automattor — 4 years ago
- Resolution set to fixed
- Status changed from new to closed

I removed some keywords, a list of keyword that are used can be found at: http://codex.wordpress.org/Reporting_Bugs#Trac_Keywords
This is a good idea and I bet there are people that would rather change from the [...] to something else. Plus there is a filter for the_content_more_link, so shouldn't excerpt have one too?