I’d like to know if it is possible for me to manipulate the output of wp_head()?
Right now I’m using the Yoast SEO plugin to add some social tags into my posts (og:*).
Now this site is an remake of an older umbraco based blog, and the permalink structure is different, so the old urls are 301 to the new ones, but addthis requires the old url to keep the right count, so we have a custom field that provides the “addthis:url” when required…
Unfortunately facebook & twitter do not use that url, but they use the pages “og:url” meta tag, that the plugin provides (which points to the new url), and seems that it can not be manipulated in the post.
My idea is that before the wp_head is printed out, I would basically do an search-and-replace to change that “og:url” to correct one, but I have not found a way to do that…
So what I’m asking is that is my idea correct and how to do it, or is there a better/official way to fix this solution?
Information attached to the
wp_head
action hook isecho
ed (if it needs to beecho
ed) as it occurs. There is no “wp_head” content string that you can search and replace.you are interested in manipulating and hope that there hooks built
in that will help you out.
Or try output buffering around
wp_head
:You could do one of the following things, for instance:
wp_head
and output your own meta information. This could be defined as a post meta.// Edit
I just had a short glimpse at the plugin.
If you want to alter the
og:url
, you can do this like so:This code is untested, though.
I managed to find this post:
https://wordpress.stackexchange.com/a/75168/45611
It basically had what I needed.
Thanks people, you were helpful!