Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#10395 closed enhancement (fixed)

wp_trim_excerpt() filterable [...] string

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


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 5 years ago.
hayadan-co-il.PNG (137.1 KB) - added by ramiy 5 years ago.

Download all attachments as: .zip

Change History (10)

ramiy5 years ago

comment:1 ramiy5 years ago

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

comment:2 dcole075 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?

comment:3 follow-up: ramiy5 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.

ramiy5 years ago

comment:4 Denis-de-Bernardy5 years ago

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

comment:5 in reply to: ↑ 3 stewartKnapman5 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

function moreLink($content){
	return preg_replace('/(\[...\])/','<small><a href="'.get_permalink().'">More ...</a></small>',$content);
add_filter('the_excerpt', 'moreLink');

comment:6 dd325 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');

comment:7 ramiy5 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.

comment:8 automattor5 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.