• Resolved gopalb123

    (@gopalb123)


    HI,

    My code is:

    <?php $text = $post->post_excerpt;if (strlen($text) > 40) {
    $text = substr($text,0,strpos($text,' ',40)); } ;
    $text = $text . '';
    echo apply_filters('the_excerpt',get_the_excerpt().'<a href="'.get_permalink().'"> Read More </a>'); ?>

    I want to limit expcerpt lenth in 40 wards, but i cant do it with above code.

    please help me…

Viewing 3 replies - 1 through 3 (of 3 total)
  • You need to use a filter in your theme’s or child theme’s functions.php file:

    http://codex.wordpress.org/Function_Reference/the_excerpt#Control_Excerpt_Length_using_Filters

    Thread Starter gopalb123

    (@gopalb123)

    Thanks Kjodle,

    I write filter in my function.php

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

    but its not working…something is wrong in my category.php code….

    Thread Starter gopalb123

    (@gopalb123)

    Hi
    I solved my problem….

    in function.php

    function get_excerpt($count){
      $permalink = get_permalink($post->ID);
      $excerpt = get_the_content();
      $excerpt = strip_tags($excerpt);
      $excerpt = substr($excerpt, 0, $count);
      $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
      $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
      return $excerpt;
    }

    and add this code to your desired place…
    <?php echo get_excerpt(125); ?>

    125 is your word limit…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Expcerpt length’ is closed to new replies.