简体   繁体   中英

How can I enlarge the default 55 words on excerpt function in wordpress?

I am usign wordpress and I have used this code on function.php-

function excerpt($num) {
$limit = $num+1;
$excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt)." <a href='" .get_permalink($post->ID) ." ' class='".readmore."'>বিস্তারিত পড়ুন</a>";
echo $excerpt;
}

And this code to post-loop.php- " <?php echo excerpt('55'); ?> "

If I change the 55 to 20 then the word the front post of my site become 20 words but if I use 60 instead of 55 then it does not become 60 words, If I reduce the size then the word becomes smaller but if I enlarge the size then the words do no enlarge by count, 55 is the max??

Can you kindly help me? Please let me know how I can put more than 55 words on my homepage, the website link is- http://it-bari.com , there is default 55 words on homepage,,,,,,,

Please help me. Thanks.

function vaf_custom_excerpt_lengh( $length ) {
return 99; //This is the number of length you want to set as default excerpt length
}
add_filter( 'excerpt_length', 'vaf_custom_excerpt_lengh',10 );

//The last parameter 10 is the priority which by default is 10. Lower values means higher priority to execute earlier..(try with values less than 10 if it doesn't work)

using this fucntion you can filter excerpt in wordpress.

function filter_function_name( $excerpt ) {
     return substr($excerpt,0,55);

}
add_filter( 'get_the_excerpt', 'filter_function_name' );

get the excerpt in any page using this function.

the_excerpt();

I hope this is working for you.

The function you're using, excerpt() , will limit the number of words in the default excerpt.

By default excerpts are limited to 55 words. When you run your function and pass in 20 for example the function takes the default excerpt and cuts it down to 20 words.

You can't cut the number of words to more than you had in the first place which is why any number above 55 won't work for you.

Instead you want to filter the number of words in excerpts and apply it to the homepage.

Add the code below to functions.php:

function wpse_filter_excerpt_length( $length ) {
    if ( is_front_page() ) {
        return 60; // change this to number of words you want on homepage.
    } else {
        return $length;
    } 
}
add_filter( 'excerpt_length', 'wpse_filter_excerpt_length', 999 );

The code I've added above works on the assumption you've set your front page in the admin (Settings -> Reading). Otherwise replace is_front_page() with is_home() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM