I am currently working on this and I have some things to say / ask:
- add_term_meta() actually adds metadata for the selected term, but as a "property" metadata for that term, so, if I have a tag called "london" and I want to add a description, I can get it done by add_term_data, and whenever I want to have it, just have to take: get_term('london')->description, in the same way I could insert a wikidata url to the tag object, but this would not actually update the html meta tags in the website header.
- Wordpress meta tags page explains this briefly and explains why are they not added automatically in wordpress and how to add them manually... by editing header.php theme file... =(
- In first place, I dont feel that any user would accept a plugin that changes his header.php or forces him to use a pre-edited for the plugin purposes one (I would not). I just need to add some <meta> labels.
- In second place, I need to change those <meta> labels depending on the page and the tags or categories displayed on it, so a unique header.php will not fit in.
Saying that, I see two approaches (that are not final or perfect)
- Somehow, someway, edit a field on the headers.php to fill it with the proper meta labels.
- maybe this way-> hooking to wp_head and 'echoing' the proper meta labels.
And this is how I am doing it.
I hook a function to "wp_head" hook, that is triggered when header.php is loaded (every time a page is) , I load the tag list and the options array (where our associations for every tag are) and check for the page that is being loaded with "is_page". The Idea is to check if the page link coincides with the tag page link - get_tag_link($tag->term_id) does the magic - and if there is an option set for our tag name in plugin options. If ok, will echo the <meta> label into the header.
This way I don't touch user's header.php, making this less intrussive.
For the moment something is not ok, I don't know if is the page check or if the options list is not loaded properly, so the meta tags do not coincide with the page, but they are added to the header:
(meta property are tag_names, just a test to check if they are added to the header)
I'd like to add, that once this is done, adding a form to include other common meta labels (like author, contact, copyright...) is not a huge effort, just in case you want to add that functionality to the plugin.
Of course, if somebody thinks there is any problem on implementing the metadata addition this way, or knows a better way to do it, I will be happy to hear it =)