Page MenuHomePhabricator

<meta> tags addition to specific pages
Open, MediumPublic

Description

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)

  1. Somehow, someway, edit a field on the headers.php to fill it with the proper meta labels.
  2. 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 =)

Thank you!

Related Objects

Event Timeline

Zeko created this task.Oct 24 2017, 12:06 PM
Zeko added a comment.Oct 26 2017, 11:56 AM

Hello, just wanted to keep you informed =)

Now I'm able to add metadata to tag pages:


Just metadata for that tag name will be added.

And to posts:


Where metadata for every tag in the post will be added.

I'd like you to specify what metadata, names and properties you'd like to add.

thiemowmde triaged this task as Medium priority.Oct 27 2017, 12:13 PM
thiemowmde added a project: patch-welcome.
Lydia_Pintscher moved this task from incoming to monitoring on the Wikidata board.Dec 18 2017, 2:48 PM

@Zeko: Hi! Could you maybe share a status update? Are you still working (or still plan to work) on this task? Is there anything that others could help with? (If you do not plan to work on this task anymore, please remove yourself as assignee (via Add Action...Assign / Claim in the dropdown menu) so others could in theory work on it.) Thanks a lot!

Aklapper removed Zeko as the assignee of this task.Jan 3 2020, 12:10 AM

@Zeko: I am resetting the assignee of this task because there has not been progress lately (please correct me if I am wrong!). Resetting the assignee avoids the impression that somebody is already working on this task. It also allows others to potentially work towards fixing this task. Please claim this task again when you plan to work on it (via Add Action...Assign / Claim in the dropdown menu) - it would be welcome! Thanks for your understanding!