-
onlygio
Hello,
I have created a small plugin that modifies the author string using the generate_post_author_output filter.
I have installed it on several sites and it works on almost all of them.
Strangely, on some sites, it doesn’t work, and I’ve noticed that this hook is not being called.
Is there a way to debug this behavior? The plugins installed on all the sites are the same, and I can’t understand why this hook is not being called.
Thank you.
-
David
Hi there,
can I see one of the sites its not working on?
It maybe that the themes default post meta has been replaced with a GP block element or other plugin -
onlygio
Hello,
thanks for your attention.Here is an example where the hook is not working:
https://napoli.cityrumors.it/2024/07/31/devi-muoverti-in-treno-ad-agosto-da-napoli-sara-una-tragedia/In the entry-meta, there is the date and the author. In contrast, here is an example where the hook is working correctly:
https://www.computer-idea.it/svegliati-con-la-tua-canzone-preferita-tutti-i-passaggi-in-questa-guida/In the entry-meta, you can see “scritto da” and “a cura di,” which is the expected behavior.
Both configurations are the same with no additional plugins or GP blocks.
Is there a way to debug this behavior? I would appreciate any guidance on why this hook is not being called on some sites.
Thank you.
-
Can you share the PHP Snippet you’re using ?
-
onlygio
if (isset($enable[0]) && $enable[0] == 1) { add_filter( 'generate_post_author_output', [$this,'ai_post_render_author'] ); }
function ai_post_render_author() { global $post; $author = esc_html(get_the_author()); $author_archive = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); $author_image = get_avatar( get_the_author_meta( 'ID' ), 25 ); $author_tooltip = ''; $editor_row = ''; $author_image = '<img alt="" src="'. get_site_icon_url() . '" srcset="'. get_site_icon_url() . ' 2x" class="avatar avatar-25 photo" height="25" width="25" decoding="async">'; $author_tooltip = '...'; $editor_id = get_post_meta($post->ID, '...', ''); $editor_archive = esc_url( get_author_posts_url( $editor_id[0] ) ); $editor_params = get_user_by( 'ID', $editor_id[0] ); $editor_image = get_avatar( $editor_id[0], 25 ); $editor = $editor_params->display_name; $editor_tooltip = '...'; $editor_row = ' ...'; } $entry_meta = '<div class=""><span class="byline">'; $entry_meta .= '<span class="author vcard" itemtype="https://schema.org/Person" itemscope="itemscope" itemprop="author">Scritto da <span class="tooltip"><a class="url fn n" title="Vedi tutti i post di ' . $author . '" rel="author" itemprop="url" href="' . $author_archive . '"><span class="author-name" itemprop="name">' . $author . '</span></a>' . $author_tooltip . '</span></span>'; $entry_meta .= $editor_row; $entry_meta .= '</span></div>'; return $entry_meta; }
-
What happens if you remove the condition around the
add_filter
? -
onlygio
nothing, I’ve just tried without conditions, it’s like doesn’t exists the hook
-
Have you tried purging the site caches ?
-
onlygio
Yes, I have tried that. I also installed Query Monitor, and it appears that the hook is not being called. This remains a significant mystery.
-
So of its not page caching or op caching.
Then what over custom functions are on the site ? Perhaps theres a conflict -
onlygio
I’m conducting a more detailed debug. I’ve noticed that on sites where it works, disabling Yoast also causes it to stop working. At this point, I suspect the issue is with Yoast.
What’s odd is that disabling Yoast also prevents generate_post_author_output from functioning. Have you ever encountered this issue?
-
I think there might be an option in Yoast which is conflicting with the code.
You might need to do some testing in the Yoast plugin.
-
onlygio
The most curious thing is that if I disable Yoast, the hook stops working. I’ll keep looking into it. Thanks for the help.
-
onlygio
[SOLVED]
I solved the issue. Essentially, the author change functionality was enabled by another hook with the_content, so that was the problem. Yoast was overwriting the content, causing instability in the behavior of other functions.
Thank you for your time.
Have a good day at work. -
Ah, thanks for explaining the cause of the issue.
Glad to hear its working!
- You must be logged in to reply to this topic.