Trying to inject twitter metadata into using wp_head action in functions.php – get_the_excerpt() returns null

So I followed the “Add Twitter Cards without plugins” this tutorial for how to add twitter metatags into the header using the wp_head method.

I have pretty much taken the code as is, and put it in my functions.php.

This works great for all the metatags except get_the_excerpt() which seems to just return nothing and so the metatag ends up looking like this:

<meta name="twitter:description" value="">

I thought that the line: global $post; meant that I should have access to all the post data in this code in the same way as if I was calling these functions in the loop.

Does anybody know why it isn’t working? Or if there are better ways of doing it than this?

Any help is appreciated.

Thanks,

Poncho

0

Leave a Comment