• Resolved batschi

    (@batschi)


    Hello guys,

    I have a little problem.
    After I have added

    add_action('init', 'my_custom_init');
    function my_custom_init() {
    	add_post_type_support( 'page', 'excerpt' );
    }

    to my functions.php, the

    function excerpt_length( $length ) {
    	return 20;
    }
    add_filter( 'excerpt_length', 'excerpt_length' );

    doesn’t work anymore.

    All pages have a excerpt and I want to display an excerpt of 20 words only. Could anyone help me with this problem?

Viewing 11 replies - 1 through 11 (of 11 total)
  • function my_excerpt_length($length) {
    	return 20; // Or whatever you want the length to be.
    }
    add_filter('excerpt_length', 'my_excerpt_length');
    Thread Starter batschi

    (@batschi)

    this is what I added, but after I have added the first piece of code the filter excerpt_length doesn’t work anymore.

    Sorry – my bad. It might be worth raising this as a bug in Trac if you can replicate it in the Twenty Ten theme.

    Thread Starter batschi

    (@batschi)

    I can replicate it in the Twenty Ten theme.
    So I think this could be a bug for the page excerpt if you use a excerpt and not the more-tag.

    It looks like the excerpt_length filter isn’t being applied correctly. Does it fail in Posts as well?

    Thread Starter batschi

    (@batschi)

    yep, the same problem with posts.

    EDIT: but if I use the more-tag, it works correctly

    if I use the more-tag, it works correctly

    The more tag only works with the_content() – not the_excerpt(). Are you sure that the relevant template files are using the_excerpt()?

    Thread Starter batschi

    (@batschi)

    yep – I have added the_excerpt() but I don’t mean the more-tag sorry.
    I meant if the excerpt field is empty in the backend for a page then I will get the correct length from the content. But I want to use the excerpt field.

    Ah! I’m not 100% sure that the excerpt_length filter will run on the Optional Except field – if that’s what you mean. I’d guess that the assumption was, if you manually added an excerpt, you’d want it all to be shown. The filter only runs on the auto-generated excerpt.

    Thread Starter batschi

    (@batschi)

    ah okay – the filter will work with the automatically generated excerpt only?

    As I understand it, yes.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Excerpt length doesn't work’ is closed to new replies.