php – Resumo de Posts no WordPress

Question:

I need the size of the summary of posts on my frontpage to be different from the size of the summary of the page where all posts are displayed ( home.php ).

In my functions.php file I put the following code:

//adiciona um novo tamanho de resumo de posts
function novo_tamanho_do_resumo($length) {
    return 15; //15 palavras
}
add_filter('excerpt_length', 'novo_tamanho_do_resumo');

The problem with this code is that the abstract has 15 words on all pages, however I need that in frontpage.php is 15 words, and that in home.php has 100 words.

Answer:

When you create an action for a certain hook, inside this function there can be checks for what you need and return the value accordingly.

In your case you can do:

//adiciona um novo tamanho de resumo de posts
function novo_tamanho_do_resumo ( $length ) {

    if ( is_frontpage() ) { // ou qualquer outro if pra verificar em qual página está

        return 15; //15 palavras

    } else if ( is_home() ) {

        return 100; //100 palavras

    } else {

        return 55; //valor padrão

    }

}
add_filter( 'excerpt_length', 'novo_tamanho_do_resumo' );
Scroll to Top