Il codice cosi' che ti ho postato andrebbe messo nel functions.php.
Ci pensa add_action() a caricarlo ad ogni caricamento pagina (wp_head() dev'essere presente in header.php pero').
Se usi add_action() quindi, non serve richiamarlo a mano nei template.
In alternativa puoi mettere il codice nei singoli template( es single.php )
Codice PHP:
if (is_singular() and !is_admin()) { $count = get_post_meta(get_the_ID(),'_post_views',true); if (!is_numeric($count) or $count == '') { $count = 1; delete_post_meta(get_the_ID(),'_post_views'); add_post_meta(get_the_ID(),'_post_views', $count); }else{ update_post_meta(get_the_ID(),'_post_views',$count+1); } }
senza la parte di add_action() cosi' come scritto qui sopra oppure creare in functions.php
Codice PHP:
my_track_post_views(){ if (is_singular() and !is_admin()) { $count = get_post_meta(get_the_ID(),'_post_views',true); if (!is_numeric($count) or $count == '') { $count = 1; delete_post_meta(get_the_ID(),'_post_views'); add_post_meta(get_the_ID(),'_post_views', $count); }else{ update_post_meta(get_the_ID(),'_post_views',$count+1); } } }
e nei singoli template richiamare solo my_track_post_views();
Che errori ti da esattamente?