1

I have a theme on WordPress theme review queue and I'm using the below code to change excerpt length.

function theme_slug_excerpt_length( $length ) {
    return 50;
}
add_filter( 'excerpt_length', 'theme_slug_excerpt_length', 999 );

Now theme reviewer ask to apply that limit on only front end, which is it should not impact on admin side.

So will this below code work?

function theme_slug_excerpt_length( $length ) {
    if ( is_admin() ) {
        return $length;
    }
    return 50;
}
add_filter( 'excerpt_length', 'theme_slug_excerpt_length', 999 );

Please help me. Thanks in advance.

Regards Ponvendhan

  • Yes, the filters only show on the front end. They'll still be able to enter longer excerpts in wp-admin. – WebElaine Apr 24 '17 at 17:03
  • You could simplify your code to return is_admin() ? $length : 50;. Are you allowed to modify the rest-api response from theme files? It looks like is_admin() will not prevent that. Note how the TwentyTen and TwentyEleven use the excerpt_length filter without any restrictions. – birgire Apr 24 '17 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.