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(); ?>
</head>
<body>
<div id="wpseo_head">
<?php do_action('wpseo_head'); ?>
</div>
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]);
setup_postdata($post);
ob_start();
do_action('wpseo_head');
$yoast_seo_tags = ob_get_contents();
ob_end_clean();
$yoastSeoTags = stripslashes($yoast_seo_tags);
Question is
please explain this and how I can successfully grab the output of the wpseo_head() call within an API callback?