add_filter the_content in functions.php non funziona
Voglio aggiungere un add_filter per the_content nel functions.php del mio tema. Ho inserito del codice che dovrebbe semplicemente visualizzare un echo ma sembra che il mio filtro non venga applicato.
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> was last modified: <span class="updated"> '.
//$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
   // }
    return $content;
    }
 add_filter('the_content', 'add_mod_hatom_data');
Ho provato a chiamarlo così:
add_filter('the_content', 'add_mod_hatom_data', 99);
O a cambiare la posizione in cima al functions.php senza successo.
Devo abilitare da qualche parte add_filter o viene sovrascritto da qualche altra funzione? NOTA: Nel mio template dei post singoli ho:
<?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> <!-- fine intestazione articolo -->
                        <footer>
                            <!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Tags","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
                        </footer> <!-- fine piè di pagina articolo -->
                    </article> <!-- fine articolo -->
                    <?php endwhile; ?>          
                    <?php else : ?>
                    <article id="post-not-found">
                        <header>
                            <h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
                        </header>
                        <section class="post_content">
                            <p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
                        </section>
                        <footer>
                        </footer>
                    </article>
                    <?php endif; ?>
                </div> <!-- fine #main -->
            </div> <!-- fine #content -->
<?php get_footer(); ?>
                
                            Questo accade perché la variabile '$content' è vuota. Il modo in cui stai utilizzando questo filtro è corretto. Invece di usare 'echo', inserisci i tuoi valori nella variabile '$content' e poi il 'return $content' effettivamente li mostrerà sulla pagina. Prova così:
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> è stato modificato l'ultima volta: <span class="updated"> '.
//$t.'</span> da <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
   // }
    return $content;
    }
 add_filter('the_content', 'add_mod_hatom_data');
                            
                                Anche questo non funziona. Ho commentato il codice in questa funzione e ho messo echo per dimostrare che la funzione non verrà chiamata. Ho testato anche il tuo codice 'perrrrr...' non viene visualizzato anche se l'ho inserito nella variabile $content. Sospetto che sia correlato al fatto che nel template del singolo post ho the_post() e non the_content() o qualcosa del genere?
                            Radenko Zec
                        Puoi aggiungere nel tuo template del singolo post il codice così possiamo vederlo. (Tutto il codice)
                            Matt Royal
                        Questa parte del template del singolo post è chiamata loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
All'interno del loop è necessario richiamare il contenuto:
<?php the_content(); ?>
Sostituisci il tuo template del singolo post con questo e verifica se ora funziona:
<?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>
                </div>
            </header> <!-- end article header -->
            <footer>
                <!-- <?php the_tags('<p class="tags"><span class="tags-title">' . __("Tags","wpbootstrap") . ':</span> ', ' ', '</p>'); ?> -->
            </footer> <!-- end article footer -->
        </article> <!-- end article -->
        <?php endwhile; ?>          
        <?php else : ?>
        <article id="post-not-found">
            <header>
                <h1><?php _e("Non trovato", "wpbootstrap"); ?></h1>
            </header>
            <section class="post_content">
                <p><?php _e("Spiacenti, ma la risorsa richiesta non è stata trovata su questo sito.", "wpbootstrap"); ?></p>
            </section>
            <footer>
            </footer>
        </article>
        <?php endif; ?>
    </div> <!-- end #main -->
</div> <!-- end #content -->
<?php get_footer(); ?>