Ticket #10395 (closed enhancement: fixed)

Opened 3 years ago

Last modified 2 years ago

wp_trim_excerpt() filterable [...] string

Reported by: ramiy Owned by:
Priority: normal Milestone: 2.9
Component: Template Version: 2.8
Severity: normal Keywords: has-patch
Cc: r_a_m_i@…, ramiy

Description

I added new filter to wp_trim_excerpt() function according to #7778. Just like the #7778 filter give us the ability to control over $excerpt_lenght, the new filter give us the ability to control over $excerpt_more string [...] .

Attachments

10395.patch Download (575 bytes) - added by ramiy 3 years ago.
hayadan-co-il.PNG Download (137.1 KB) - added by ramiy 3 years ago.

Change History

ramiy3 years ago

  • Cc ramiy added
  • Keywords has-patch,excerpts, wp_trim_excerpt, excerpt_more added
  • Keywords has-patch added; has-patch,excerpts, wp_trim_excerpt, excerpt_more removed

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?

comment:3 follow-up: ↓ 5   ramiy3 years ago

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.

ramiy3 years ago

  • Component changed from General to Template
  • Milestone changed from 2.8.2 to 2.9

comment:5 in reply to: ↑ 3   stewartKnapman2 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');

comment:6   dd322 years ago

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.

  • Status changed from new to closed
  • Resolution set to fixed

(In [11907]) Give plugins and themes simple control over the text displayed at the end of an autogenerated excerpt. Fixes #10395 props ramiy.

Note: See TracTickets for help on using tickets.