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.
I am using 25 words for the teaser view for a particular content type, however the token for the meta description [node:summary] seems to use 25 characters for the trim value. Do you know how I can work around this, is there a token for the smart trimmed value of the body in the Metatag module?
Thanks for the help!
Comments
Comment #1
interdruper CreditAttribution: interdruper at Interdruper commentedThe problem is that the Smart Trim module uses the same element ('trim_length') for storing the length in chars and the length in words. This element is used by the core's Node module for building the value of the [node:summary] token. And the Node module assumes that this length is about characters.
I run into this problem using the [node:summary] token (as usual) for the description metatag in the Metatag module, and finding that the metatag length was very short (even shorter if the body starts with HTML tags).
Here is the code that fix the problem for me, in fact it is just a workaround. If the approach is interesting for someone else, I can provide it in form of patch to the Smart Trim module.
Comment #2
duncan.moo CreditAttribution: duncan.moo as a volunteer commentedI have taken a slightly different approach, which I would appreciate others' input on. I have submitted a patch which adds a dynamic smart trim token (https://www.drupal.org/node/2782455).
The patch does not trim on word-count though, which was part of your OP, but it does respect word boundaries.
Comment #3
volegerThanks for the code snippet @interdruper !
Module introduce trim_type words which not supported during token generation, so that is reasonable that module must provide token alteration to respect field teaser settings.
I will postpone this issue in favor of #2782455: Smart Trim Tokens for text with summary fields.