• I’ve got the latest version of wordpress installed.

    I’m writing text into the excerpt box in the ‘add new post’ box of the admin system and then calling this via the_excerpt() function.

    I’ve tried several ways of changing the default excerpt length from 55 to 10 words, including changing the excerpt_length in the formatting.php file, as well as adding the well known functions within my own theme’s functions template that I found in the codex.

    Can anyone give me any pointers or codes where they have been successful in trimming the excerpt length?

    Much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Put this in your functions.php

    /* Create excerpt with 10 words and preserved HTML tags */
    function my_wp_trim_excerpt($text) {
    {
      if ( '' == $text ) {
      $text = get_the_content('');
      $text = apply_filters('the_content', $text);
      $text = str_replace(']]>', ']]&gt', $text);
      $excerpt_length = 10;
      $words = explode(' ', $text, $excerpt_length + 1);
      if (count($words) > $excerpt_length) {
        array_pop($words);
        array_push($words, '[...]');
        $text = implode(' ', $words);
        }
      }
    return $text;
    }
    
    // remove WordPress default excerpt filter
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    // Add our custom filter with low priority
    add_filter('get_the_excerpt', my_wp_trim_excerpt, 20);

    Peter

    you can use like that

    <div class="entry">
    			<div class="imgc5">
    			<?php echo get_the_image(); ?>
    			</div>
    			<?php $excerpt = 130; //chracter number here
    	$excerpt_more_text = __('Read More','options').' &raquo;';
    	$odd_post = 'odd'; $i = 1;?>
    		<?php limit_content($excerpt, $excerpt_more_text); ?>
    				</div>
    	</div>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘the_excerpt() length – changing the default not working’ is closed to new replies.