set custom post excerpt length

2.88K views
no comments
26 Sep 2016 9:45 pm

#wordpress is show too much text the the_excerpt, so we need to customize it for showing shorted excerpt paragraph. copy this code and paste into your current active theme’s functions.php file

function my_custom_excerpt_length($length){
    return 100;
}
add_filter('excerpt_length', 'my_custom_excerpt_length', 999);

set different post excerpt length for mobile devices

wp_is_mobile is builtin function of #wordpress which return true when it found mobile text in #user_agent of your device

function my_custom_excerpt_length($length){
    return wp_is_mobile() == true ? 50 : 100;
}
add_filter('excerpt_length', 'my_custom_excerpt_length', 999);

 

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>