Modifying meta tags after doing ajax call in plugin

It took me a while of tinkering with the hooks, but in the end, I fixed it by loading the post earlier. Instead of loop_start:

$this->loader->add_action('loop_start', $plugin_public, 'mp_display_post');

I used get_header:

$this->loader->add_action('get_header', $plugin_public, 'mp_display_post');

This worked properly because now the post information is loaded before wp_head gets called, and therefore I can use the loaded post’s data for the open graph tags, the regular way:

add_action( 'wp_head', 'insert_og_in_head', 5 );