Support » Fixing WordPress » Changing Excerpt Length

  • Hi,

    Im trying to change the excerpt length shown in the post previews on the homepage. the loop php file is currently outputting ‘the_excerpt();’ in order to get the default output.

    i have tried a few plugins, recommended functions to function.php and even modify the core file in wp-include, but everytime i get the same results – which is no change.

    could anyone give me a hand with this ?

    thank you

Viewing 15 replies - 1 through 15 (of 19 total)
  • This will really depend on your theme, so which theme are you using would be a start, if it is a well known or free theme then it will be easier to answer?

    The standard code should work, if it is not then it is likely your theme is changing it back somewhere else in the code.

    Regards

    David

    Thread Starter zubair04

    (@zubair04)

    hi,

    Im using the twentyten theme, the basic theme that came with the wordpress package, but i have edited the styling quite a bit.

    Add the below code in your functions.php

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

    Increase the count as per your wish.

    Thread Starter zubair04

    (@zubair04)

    Hi, thanks for the help,

    ive tried adding this , and other similar functions but to no avail.

    if you are editing twenty ten directly, then the excerpt length is set in functions.php:

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

    Are you using a child theme or the twenty ten theme?

    You should really be using a child theme then this would go in the after_setup_theme hook!

    In twenty ten you already have the function

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

    * To override this length in a child theme, remove the filter and add your own
    * function tied to the excerpt_length filter hook.

    So you could code:

    remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
    
    function my_twentyten_excerpt_length( $length ) {
    	return 50;
    }
    add_filter( 'excerpt_length', 'my_twentyten_excerpt_length' );

    HTH

    David

    Thread Starter zubair04

    (@zubair04)

    ive tried editing the return figure around line 231 in my functions.php file in theme/twentyten but still no luck 🙁

    Thread Starter zubair04

    (@zubair04)

    i dont think im using a child theme, i have just been editing the php/css files in the twentyten theme folder, i will now try the suggestion from David

    Thread Starter zubair04

    (@zubair04)

    Ive tried davids code but it has not worked.

    http://thecypher.co.uk

    this is the site im working on. at the minute i am using a plugin which generates a thumbnail from the image in a post. im just wondering if that has anything to do with it ?

    thanks

    Trial and error!

    Something is changing it as the word count is 56, the theme is set at 40, deactivate the plugins and count the words in the excerpt, change the value and try again, them reactivate the plugins one at a time and see if it goes back to 56.

    HTH

    David

    Thread Starter zubair04

    (@zubair04)

    ah okay so it must be a plugin thats overriding the theme,

    il try disabling each plugin and see what happens.

    thanks for your help

    Thread Starter zubair04

    (@zubair04)

    ok so when i deactivate the ‘thumbnail for excerpts’ plugin . the site shows the full post including the large image and the full text.

    so its definitely to do with this plugin, unfortunatley the settings for this plugin does not have an option to edit the excerpt length…

    Thread Starter zubair04

    (@zubair04)

    thanks for your help everyone , the problem was in the php file provided by this plugin , at the bottom was a function where it redefined teh excerpt length

    Grats! I hate it when plugins do stuff like that!
    🙂

    thanks for your help everyone , the problem was in the php file provided by this plugin , at the bottom was a function where it redefined the excerpt length

    If the plugin is well supported might be worth contacting the author, tell them of the issue and they may add this as a setup option.

    It does not make a lot of sense to have set it 56 words only to pad it out to the image height, not considering different themes use different font sizes, and different languages use different word lengths, so it should be a set option, or left alone.

    Add the plugin name to the tags so others and maybe the author will be able to find this topic.

    David

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Changing Excerpt Length’ is closed to new replies.