Archived topic
Insert php code with hook > archive page
7 replies · Started by M on October 11, 2021
Hi, I want to insert a little piece of code in the 2 column blog overview with every post.
I tried to do that with elements>hook (php execute) "generate_after_archive_decription" (location: tried entire site also) but nothing shows up.
De code I want to insert:
echo kk_star_ratings();
This is the place where I want the code to be inserted:

What am I doing wrong?
Hi there,
that hook is for the main description of the archive page.
See here for the hooks within the individual posts inside the loop:
https://docs.generatepress.com/article/hooks-visual-guide/
Try the after_entry_header hook and set the Priority to 50
When I replace the php code with echo '<p>Hello World</p>' it gets visible when I use after_entry_header, but the echo kk_star_ratings(); is still not showing unfortuneatly.
Hi Mervin,
What's the exact code you added to the hook?
And can you make sure theExecute PHPbox is checked?
Let me know :)
the exact code is:
<?php
echo kk_star_ratings();
?>
And yes, the Execute PHP box is checked.
can you do a var_dump() of kk_star_ratings() function? to be sure if it actually has any value in it.
Example:
<?php
$kk_star_rating = kk_star_ratings();
var_dump($kk_star_rating);
?>
This is what I get back:
string(0) ""
Is this from a single post page?
If it's returning string 0 then that means it's empty value.
I've not exactly sure how that plugin's developer coded the kk_star_ratings() function but if it doesn't output any value on archive page then perhaps the function was coded only for single post pages.
But you may have to confirm this with the plugin's developer.
https://wordpress.org/support/plugin/kk-star-ratings/