add_filter para the_content en functions.php no funciona
Quiero agregar un add_filter para the_content en el functions.php de mi tema. He añadido código que simplemente muestra un echo pero parece que mi filtro no se aplica.
function add_mod_hatom_data($content) {
// $t = get_the_modified_time('F jS, Y');
//$author = get_the_author();
// $title = get_the_title();
//if(is_single()) {
echo 'perrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr';
// $content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> fue modificado por última vez: <span class="updated"> '.
//$t.'</span> por <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
// }
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');
He intentado llamarlo así:
add_filter('the_content', 'add_mod_hatom_data', 99);
O cambiar su posición al inicio del functions.php sin éxito.
¿Necesito habilitar add_filter en algún lugar o está siendo anulado por alguna otra función? NOTA: En mi plantilla de post individual tengo:
<?php get_header(); ?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-8 clearfix" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<header>
<div class="page-header clip_content single-post">
<div class="page-header">
<h1 class="single-title-wg" itemprop="headline">
<?php $category = get_the_category();
if ($category[0]) {
echo '<b>'.$category[0]->cat_name.' '.$post->ID.'</b>';
}
?>
</h1>
<h4 class="single-title" itemprop="headline">
<p class="lead">
<?php the_title(); ?>
</p>
</h4>
</div>
<div class="item_footer">
</div>
<?php $category = get_the_category();
if ($category[0]) {?>
<p class="authorParagraph">
<?php echo '<a href="' . get_category_link($category[0]->term_id) . '" class="clearfix">' . $category[0]->cat_name . '</a></p>';
}
?>
</div>
</div>
</header> <!-- fin del encabezado del artículo -->
<footer>
<!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Etiquetas","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
</footer> <!-- fin del pie de página del artículo -->
</article> <!-- fin del artículo -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("No encontrado", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Lo sentimos, pero el recurso solicitado no se encontró en este sitio.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- fin de #main -->
</div> <!-- fin de #content -->
<?php get_footer(); ?>

Esto ocurre porque la variable '$content' está vacía. La forma en que estás usando este filtro es correcta. En lugar de usar 'echo', coloca tus valores en la variable '$content' y luego el 'return $content' efectivamente lo imprimirá en la página. Prueba esto:
function add_mod_hatom_data($content) {
// $t = get_the_modified_time('F jS, Y');
//$author = get_the_author();
// $title = get_the_title();
//if(is_single()) {
$content = 'perrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr';
// $content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> fue modificado por última vez: <span class="updated"> '.
//$t.'</span> por <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
// }
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');

Esto tampoco funciona. He comentado el código en esta función y he puesto un echo para probar que la función no se llama. También he probado tu código 'perrrrr...' no se muestra aunque lo ponga en la variable $content. Sospecho que esto está relacionado porque en la plantilla de la entrada única tengo the_post() y no the_content() o algo así?

¿Puedes agregar el código de tu plantilla de entrada única para que podamos verlo? (Todo el código)

Esta parte de la plantilla de entrada individual se llama el bucle:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Dentro del bucle necesitas llamar al contenido:
<?php the_content(); ?>
Reemplaza tu plantilla de entrada individual con esto y verifica si funciona ahora:
<?php get_header(); ?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-8 clearfix" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<header>
<div class="page-header clip_content single-post">
<div class="page-header">
<h1 class="single-title-wg" itemprop="headline">
<?php $category = get_the_category();
if ($category[0]) {
echo '<b>'.$category[0]->cat_name.' '.$post->ID.'</b>';
}
?>
</h1>
<h4 class="single-title" itemprop="headline">
<p class="lead"><?php the_title(); ?></p></h4>
<p><?php the_content(); ?></p>
</div>
<div class="item_footer">
</div>
<?php $category = get_the_category();
if ($category[0]) {?>
<p class="authorParagraph">
<?php echo '<a href="' . get_category_link($category[0]->term_id) . '" class="clearfix">' . $category[0]->cat_name . '</a></p>';
}
?>
</div>
</header> <!-- fin del encabezado del artículo -->
<footer>
<!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Etiquetas","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
</footer> <!-- fin del pie de artículo -->
</article> <!-- fin del artículo -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("No Encontrado", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Lo sentimos, pero el recurso solicitado no se encontró en este sitio.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- fin #main -->
</div> <!-- fin #content -->
<?php get_footer(); ?>
