I have a plugin that will automatically load articles from a news publisher by checking query vars in the URL.
If an article was requested, it does an AJAX call to this publisher, creates a new WP_Post and loads it in a template.
I need to add open graph meta tags to this page, and I’m at a loss.
My first failed attempt was a generic:
add_action( ‘wp_head’, ‘insert_fb_in_head’, 5 );
from the functions.php of the theme, that I would have expected to take the info from my built post, but it turns out that global $post returned NULL in this particular case.
So I’m guessing that my $post gets built later.
Adding the og meta within the body will not get them picked up by Facebook, I checked.
Grasping at straws, I tried calling that hook from within the function that builds the post, but that wasn’t even triggered.
Where does one modify the head in this case? I’m sure you will need more code, but I’m not quite sure what code to provide. I’ll update this post to accomodate to comments.
Read more here:: Modifying meta tags after doing ajax call in plugin