the_title(), the_content() y the_excerpt()

Estos tres Template Tags son los más fundamentales del Loop. Permiten imprimir el contenido del post actual dentro de la plantilla.

the_title()

Imprime el título del post actual.

// Imprime directamente
the_title();

// Con HTML alrededor (before, after)
the_title( '<h1 class="entry-title">', '</h1>' );

// Obtener el valor (para usar en PHP)
$titulo = get_the_title();
$titulo = get_the_title( 42 ); // de un post específico por ID

// Con enlace (lo más habitual en listados)
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

the_content()

Imprime el contenido completo del post, procesando shortcodes y bloques.

// Imprime el contenido completo
the_content();

// Con texto personalizado para el enlace "leer más"
the_content( 'Seguir leyendo...' );

// Obtener el valor sin imprimir
$contenido = get_the_content();

// ⚠ get_the_content() NO procesa shortcodes ni filtros
// Para tenerlos, usar apply_filters:
$contenido_procesado = apply_filters( 'the_content', get_the_content() );

the_excerpt()

Imprime el extracto del post. Si no hay extracto manual, lo genera automáticamente desde las primeras palabras del contenido.

// Imprime el extracto
the_excerpt();

// Obtener el valor
$extracto = get_the_excerpt();

// Personalizar la longitud (palabras) via filter
add_filter( 'excerpt_length', fn() => 30 );

// Personalizar el "..."
add_filter( 'excerpt_more', function( $more ) {
    return ' <a href="' . get_permalink() . '">Leer más</a>';
});

Cuándo usar cada uno

  • the_content() — en single.php y page.php (vista individual)
  • the_excerpt() — en archive.php, index.php (listados)
  • the_title() — en todos los archivos de plantilla