How do I hook into content after it is completely compiled
-
I am attempting to debug an issue I am having with a translation service API. Currently, I have a filter hook that translates content after it’s gone through the autop filter into a target language.
It looks something like this currently:
add_filter('the_content', function($content){ if(in_the_loop()){ $deepl_api_key = $_SERVER['DEEPL_API_KEY']; $translator = new \DeepL\Translator($deepl_api_key); $content_translated = $translator->translateText($content, 'EN', 'ES', ['tag_handling' => 'html'] ); return $content_translated; } return $content; }, 99);
It’s working great especially on our blogs. However, I have a content block that makes a WP_Query for posts in a featured content section. Whenever this block is included in the the content, the translation services API throws an error saying the argument must be a string.
As you can see, I gave this hook a priority of 99, which to me would mean the content at this point would be nothing but HTML. In fact, when I print $content from within this hook, it renders the content as it’s suppose to.
My questions are:
Am I correct in assuming the content is pure HTML at the point that this filter is called?
To debug, is there a final step I can hook into where not only the content but headers, nav and footer have been compiled to an html file that I can then run through this translation service?
I realize this could be a bug with the translation API or even the custom theme, but I am trying out all of my theories.
The site is running WP v5.4 and a custom theme built on Sage 9x
- The topic ‘How do I hook into content after it is completely compiled’ is closed to new replies.