Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#10395 closed enhancement (fixed)

wp_trim_excerpt() filterable [...] string

Reported by: ramiy's profile ramiy Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.8
Component: Template Keywords: has-patch
Focuses: Cc:

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 (2)

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

Download all attachments as: .zip

Change History (10)

@ramiy
15 years ago

#1 @ramiy
15 years ago

  • Cc ramiy added
  • Keywords has-patch excerpts wp_trim_excerpt excerpt_more added

#2 @dcole07
15 years ago

  • Keywords 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?

#3 follow-up: @ramiy
15 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.

@ramiy
15 years ago

#4 @Denis-de-Bernardy
15 years ago

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

#5 in reply to: ↑ 3 @stewartKnapman
15 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');

#6 @dd32
15 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');

#7 @ramiy
15 years ago

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.

#8 @automattor
15 years ago

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

(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.