Wednesday, June 19, 2013

Add own excerpt length wordrpess

 With the following code the use your new excerpt with specific length in wordpress .

Add the following code the functions.php

 function wpe_excerpt($length_callback='', $more_callback='') {
    global $post;
    if(function_exists($length_callback)){
    add_filter('excerpt_length', $length_callback);
    }
    if(function_exists($more_callback)){
    add_filter('excerpt_more', $more_callback);
    }
    $output = get_the_excerpt();
    $output = apply_filters('wptexturize', $output);
    $output = apply_filters('convert_chars', $output);
    $output = '<p>'.$output.'</p>';
    echo $output;
    }


    function wpe_excerptlength_teaser($length) {
    return 45;  // show 45 characters
    }
    function wpe_excerptlength_index($length) {
    return 30;  // show 45 characters
    }
    function wpe_excerptmore($more) {
    return '...';
    }

----------------

    function wpe_excerpt($length_callback='', $more_callback='') {
   
   global $post;
 
   if(function_exists($length_callback)){
 
    add_filter('excerpt_length', $length_callback);
    }
 
    if(function_exists($more_callback)){
    add_filter('excerpt_more', $more_callback);
    }
 
    $output = get_the_excerpt();
 
   $output = apply_filters('wptexturize', $output);

   $output = apply_filters('convert_chars', $output);

   $output = '<p>'.$output.'</p>';
   
   echo $output;
 
   }

 





No comments:

Post a Comment