Add hook on last content loop
-
I have an API that returns translated HTML to a desired target language. I am using the_content filter hook to pass the page’s HTML to the translation API. It’s working, but I noticed the_content is looping several times (on same pages, I noticed it is looping 9 times), which means the page content on the page is being passed to the translator every time it loops.
Is there a way to determine if the query is on the last loop? I tried wrapping my the_content filter in a loop_end action, but I believe this is too late — maybe I am wrong.
Here’s how the action and filter look right now.
add_action('loop_end', function(){ add_filter('the_content', function ($content){ static $i = 1; $content .= "<h2>This has looped {$i} times</h2>"; $i++; return $content; }, 99); }, 0);
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Add hook on last content loop’ is closed to new replies.