I'm developing a Wordpress website with a ReactJS SPA theme and I'm attempting to collect the necessary SEO head tags from the Yoast SEO plugin during an WP API AJAX call
I added a direct call to wpseo_head() in my header.php file just after the opening body tag
<?php wp_head(); ?>
<?php do_action('wpseo_head'); ?>
Within my api callback to load the post I capture the output of wpseo_head() and return it.
global $post, $wp_query;
$post = $_post;
$wp_query = new WP_Query(['p' => $_post->ID]);
$yoast_seo_tags = ob_get_contents();
$yoastSeoTags = stripslashes($yoast_seo_tags);
please explain this and how I can successfully grab the output of the wpseo_head() call within an API callback?