add_filter pentru the_content în functions.php nu funcționează
Încerc să adaug un filtru pentru the_content în fișierul functions.php al temei mele WordPress. Am introdus cod care ar trebui să afișeze un text simplu, dar filtrul nu se aplică.
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> a fost modificat ultima dată: <span class="updated"> '.
//$t.'</span> de <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
// }
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');
Am experimentat cu diferite apeluri precum:
add_filter('the_content', 'add_mod_hatom_data', 99);
Am încercat și mutarea codului în partea superioară a fișierului functions.php fără rezultat.
Este necesară activarea manuală a filtrului sau există un conflict cu alte funcții? OBSERVAȚIE: În șablonul single post am următoarea structură:
<?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>
</header> <!-- sfârșit antet articol -->
<footer>
<!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Etichete","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
</footer> <!-- sfârșit subsol articol -->
</article> <!-- sfârșit articol -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Nu a fost găsit", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Resursa solicitată nu există pe acest site.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- sfârșit #main -->
</div> <!-- sfârșit #content -->
<?php get_footer(); ?>

Asta se întâmplă deoarece variabila '$content' este goală. Modul în care folosești acest filtru este corect. În loc să folosești 'echo', pune valorile tale în variabila '$content' și apoi 'return $content' va afișa aceste valori pe pagină. Încearcă asta:
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> a fost modificat ultima dată: <span class="updated"> '.
//$t.'</span> de <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
// }
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');

Acest lucru de asemenea nu funcționează. Am comentat codul în această funcție și am pus echo pentru a demonstra că funcția nu va fi apelată. Am testat și codul tău 'perrrrr...' nu este afișat chiar dacă l-am pus în variabila $content. Bănuiesc că acest lucru este legat de faptul că în template-ul de single post am the_post() și nu the_content() sau ceva similar?

Poți să adaugi în template-ul tău de single post codul pentru a putea vedea. (Tot codul)

Această parte a șablonului pentru articol individual se numește bucla (loop):
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
În interiorul buclei trebuie să apelați conținutul:
<?php the_content(); ?>
Înlocuiți șablonul pentru articol individual cu acesta și verificați dacă funcționează acum:
<?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> <!-- sfârșit antet articol -->
<footer>
<!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Etichete","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
</footer> <!-- sfârșit subsol articol -->
</article> <!-- sfârșit articol -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Negăsit", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Ne pare rău, dar resursa solicitată nu a fost găsită pe acest site.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- sfârșit #main -->
</div> <!-- sfârșit #content -->
<?php get_footer(); ?>
