Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there a function for update meta tag title and description of a node programmatically?
I have many nodes in my ecommerce site that would like to upgrade with a custom script where I take these data from an excel file.
Thanks in advance.
Comments
Comment #2
DamienMcKennaYou would do something like this:
That might be slightly differently if the node is set up with translations, in that case you'd want to use the language's code instead of LANGUAGE_NONE.
Alternatively you could deal directly with Metatag's APIs:
Lets add that to the docs.
Comment #3
DamienMcKennaComment #4
giganget CreditAttribution: giganget commentedThanks a lot, just what I looking for.
Comment #5
drupalz001 CreditAttribution: drupalz001 commentedI've a similar situation:
I've a thousands of nodes with custom metatag in certain fields based on user input. Every metatag are different.
Let's say now i would like to change the canonical token from relative url to absolute url from now onwards and to update all the existing nodes.
How should i do a bulk update of all existing nodes without affecting the custom metatag?
Can i use the above method or do you have a better solution for this?
Thank you!
Comment #6
DamienMcKennaMeta tags that output a URL for the current page should be using a token to automatically insert the value, they should not be entered manually. So, if you need to change the format of a canonical URL you should change the appropriate default value (i.e. the defaults defined under admin/config/search/metatag) to have the appropriate token.
Comment #7
drupalz001 CreditAttribution: drupalz001 commentedsorry, maybe i didn't make myself clear. i am using a token for canonical url.
My point is to update the old nodes with the new canonical url (token).
Case:
Node 1 canonical url generated based on old token, output as www.example.com/node1 (without https)
I now updated the new default token to absolute url.
Node 2 canonical url generated based on new token, output as https://www.example.com/node1
Question: how to update the Node 1 automatically? The metatag Bulk Revert is not suitable here as i have custom metatag(FB image width, height) on Node 1.
i am using 7.x-1.17.
Thank you!
Comment #8
DamienMcKenna@drupalz001: Did you manually fill in the token on each node form, or did you enter it in the node (or content type) default configuration?
Comment #9
drupalz001 CreditAttribution: drupalz001 commented@DamienMcKenna
I set it at admin/config/search/metatags global type as token.
And the node type inherits it from global type.
Comment #10
DamienMcKenna@drupalz001: In that case you just have to change the value in the defaults again and then all of the existing nodes will automatically use the new value.
Comment #11
drupalz001 CreditAttribution: drupalz001 commented@DamienMcKenna
Hi, i created a new Node Type, and it works as you describe.
BUT, for my certain Node Type, it behave like this:
1) I add a new node page and i can see the metatag (on node/%/edit form) is showing "using defaults"
2) I go to admin/config/search/metatags global type and edit the Canonical URL from url-A to url-B.
3) The node i created on 1 (and all the nodes which are Using Defaults metatag), the metatag get updated by itself with canonical URL showing "url-A" (not url-B), and it apparently become custom metatag for the node (no more showing "Using Defaults" on node edit form, it showed the canonical url = url-A).
Any ideas?
Thanks for your help!
Comment #12
itsnadeem CreditAttribution: itsnadeem commentedPlease see this article to add dynamic meta tags
Comment #13
premium-ben CreditAttribution: premium-ben commented@itsnadeem that's irrelevant to the thread and it's also for D8, wheras this is about D7.