Make WordPress Core

Opened 6 years ago

Closed 5 years ago

Last modified 7 months ago

#10724 closed defect (bug) (invalid)

Cannot change excerpt_length using codex example

Reported by: jsherk Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8.4
Component: General Keywords: excerpt_length, excerpt length
Focuses: Cc:


Putting this code below (per codex) in the themes functions.php file does not make any difference to excerpt length (stays at 55 no matter what):
function new_excerpt_length($length) {

return 20;

add_filter('excerpt_length', 'new_excerpt_length');

Looking at the changes made in formatting.php, this line:
$excerpt_length = apply_filters('excerpt_length', 55);
appears that it will ALWAYS return 55 no matter what you set your add_filter too... this line is essentially the same as:
$excerpt_length = 55;
so you cannot modify it even with an add_filter call.

Change History (4)

#1 @sorich87
6 years ago

  • Cc sorich87 added
  • Resolution set to invalid
  • Status changed from new to closed

I am using the codex code on this blog : http://massolog.com/ (wp 2.8.4). And it works.

#2 @jorisw
5 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

I am having the same problem as the OP under WordPress 3.0.1.

#3 @jorisw
5 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Looks like I needed to add a low priority to the filter:

function new_excerpt_length($length) {
	return 100;
add_filter('excerpt_length', 'new_excerpt_length', 999);

That works.

#4 @DrewAPicture
7 months ago

  • Milestone 2.8.5 deleted
Note: See TracTickets for help on using tickets.