I’m trying to add some function to each loop called in the themes. What I’m doing is I add a function to count post view from here post views without plugin, to use the function I need to add this line <?php setPostViews(get_the_ID()); ?>
to single.php
, page.php
, etc.
I want to know whether I can use some hook to automatically add the <?php setPostViews(get_the_ID()); ?>
line without hard code it for each single.php
, page.php
files.
You could hook into
template_redirect
and execute a helper function:To display the post views, you have to use a later hook. I would recommend
the_content
:Just an idea, I havenât tested the code.