When creating a node (e.g. Basic page) If you leave the summary textarea blank it uses a trimmed value of full text in the body textarea as the summary.
When using [node:summary] token as the default token for the meta description, it should pull a trimmed value from the body textarea.
Workarounds:
1. Once you fill in the summary, it does indeed create the meta description
2. changing the token to [node:body] for the meta description and flushing cache does create a meta description (although too long)
I guess what I am requesting is the ability to define [node:summary] in the default meta description for content and if nothing is in that field, it pulls a trimmed version of the body field.
This is a core bug. Interested people should help work on the patches in #1300920: The [node:summary] token does not output anything for body fields without a manual summary.
There is also a patch you can use for Drupal 7: http://drupal.org/node/1300920#comment-6779546
Comment | File | Size | Author |
---|---|---|---|
#79 | metatag-n1295524-79.patch | 2.63 KB | DamienMcKenna |
#78 | metatag-n1295524-78.patch | 2.14 KB | DamienMcKenna |
#74 | node_summary_token.tar_.gz | 14.29 KB | Alauddin |
#20 | [summary-tokens]-[1295524]-[19].patch | 8.27 KB | pixelsweatshop |
#1 | 2011-09-30_12-36-39.png | 167.13 KB | Danny Englander |
Comments
Comment #1
Danny EnglanderI am having the same issue. Note that Drupal says "Leave blank to use trimmed value of full text as the summary." This implies that the token will work that way too. At the very least if this is not the case, I would not have "[node:summary]" as the default token as my users would never figure out that they have to manually put in a summery for this to work.
Comment #2
coloryan CreditAttribution: coloryan commentedI'm having the same issue - subscribing.
Comment #3
josh@pixael.com CreditAttribution: josh@pixael.com commentedsubscribing... i have the same problem...
Comment #4
Dave ReidFiled an issue with core at #1300920: The [node:summary] token does not output anything for body fields without a manual summary. We may have to drop providing a default of [node:summary] for nodes unless we provides some support in Token module to fix this.
Comment #5
netentropy CreditAttribution: netentropy commentedI am glad I found this I thought I was going batty. If someone has a snippet to pull the trimmed summary we could write a custom token.
Comment #6
Dave ReidI have some code I'm working on in Token.module to provide [node:summary]. The question is what is the default string limit the token should use? Because the default for a summary is 600 characters.
Comment #7
DamienMcKennaIsn't there a variable to control the default summary length? Or was that removed in D7?
Comment #8
Dave ReidIt's a per field instance setting now, and we can't always rely on it being available since the user could change what formatter is used on a body field.
Comment #9
netentropy CreditAttribution: netentropy commentedif you use field_get_items wouldn't it take into account the language and formatter
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm having the same issue - subscribing.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedSubscribe.
Comment #12
pixelsweatshop CreditAttribution: pixelsweatshop commented@seezee. no need to place a comment to subscribe to a thread. Use the "follow" button at the top.
Comment #13
cmseasy CreditAttribution: cmseasy commentedA (temperary) solution:
Make a view with the first 200 characters text, make a field with this view in your content type, place the field token in the Meta tag setup, hide the field with css:
Make a view named 'Meta tag description'
Make a block in that view with the fields
-- Node body:
----- Rewrite settings: max length 200 (or less) , Remove HTML tags, Remove whitespace
-- Filter: publiced and node type(s) you want
-- Contextual filter: NID: Provide default value type 'Content ID from URL'
Install module 'View reference'
For the content types you want to have a Meta description from the body vield:
Make a View reference field name 'Metatag description' fieldname 'field_metatag_description' with setup:
-- Views that can be referenced : 'Meta_tag_description blok '
-- Default value: 'Meta_tag_description blok'
Check the display of this field in your content type (s): Label: hidden, format: default view
In the Meta tag node settings page admin/config/search/metatags/config/node klick the [node:field_metatag_description] token (in Nodes tokens) in the description field.
Hide this field in css:
.view-meta-tag-description {
display: none;
}
This works for me, I had to patch viewreference because of a missing title error, the patch is here: Viewreference http://drupal.org/files/issues/1128444.patch
I first installed this with the viewfield module, but the field viewfield generates in the token is not clean text.
Remember that existing nodes need some manual adjustments (View Meta tag description block and Metatag description field)
Comment #14
andrenoronha CreditAttribution: andrenoronha commentedsubscribe!
Comment #15
pixelsweatshop CreditAttribution: pixelsweatshop commenteda.luiz.n - please use the "follow" button at the top to "subscribe" to issues now.
Comment #16
pixelsweatshop CreditAttribution: pixelsweatshop commenteddup- removed
Comment #17
blueminds CreditAttribution: blueminds commentedI have solved it by introducing new alter hook in the metatag_field_attach_view_alter().
See the code below:
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedDid you put this in your template.php? I tried that (renamed metatag_field_attach_view_alter to mytheme_metatag_field_attach_view_alter and metatag_metatags_node_token_data_alter to mytheme_metatag_metatags_node_token_data_alter), but saw no change.
Comment #19
pixelsweatshop CreditAttribution: pixelsweatshop commentedWorks like a charm blueminds
Comment #20
pixelsweatshop CreditAttribution: pixelsweatshop commentedRolled it into a patch.
Comment #21
szantog CreditAttribution: szantog commented@nicoz: I'm not so brave to try this patch. Completely remove the module's menu items is really the solution? Or I miss something?
Comment #22
blueminds CreditAttribution: blueminds commentedNot into template.php. The metatag_field_attach_view_alter() should be replaced in metatag.module and metatag_metatags_node_token_data_alter() is a new function to be added into metatag.module
The rest of the metatag.module file stays unchanged.
Comment #23
pixelsweatshop CreditAttribution: pixelsweatshop commentedComment #25
adamwhite CreditAttribution: adamwhite commentedsubscribing
Comment #26
kiwimind CreditAttribution: kiwimind commented@adamwhite, you can now simply use the Follow button at the top of an issue queue to subscribe to an issue, rather than filling the queue with a "subscribing" post.
Comment #27
adamwhite CreditAttribution: adamwhite commented@shonk I did not realize that. Cheers.
Comment #28
FiNeX CreditAttribution: FiNeX commentedThe core patch http://drupal.org/node/1300920#comment-5417072 works fine and fix this issue.
Comment #29
kristat CreditAttribution: kristat commented#17 worked like a charm. Thanks
Comment #30
FilipWitkowski CreditAttribution: FilipWitkowski commented#17 works for me!
Comment #31
heyyo CreditAttribution: heyyo commentedEven with #17 on Metatag 7.x-1.0-alpha4 or Drupal core patch on Drupal 7.10, node:summary is still not displayed on all of my content types, only one works. I'm using Display Suite, and the one which is working is using Display Suite also ! After applying both patch I cleared my cache.
The only difference between these content types, is the overriding of default metatags with the inclusion of og:image on the one which is working.
Any idea ?
EDIT: I desactivated the metatags overriding, and the node:summary is still displayed. So it doesn't seem related.
Comment #32
heyyo CreditAttribution: heyyo commentedby applying #17, when body is empty, I have the followin error:
Comment #33
heyyo CreditAttribution: heyyo commentedAfter applying Drupal Core patch, [node:summary] token is correctly generated even if summary is not manually filled.
But Metatags description and og:description is still empty.(I applyed patch #17)
Even with manually body summary filled, the metatag is also empty...
I tried to manually set metatag description and also keywords in vertical tabs menu, and guess what ? It also doesn't work !
Comment #34
tfranz CreditAttribution: tfranz commented#17 workes for me. Thanks!
Comment #35
drupalpal CreditAttribution: drupalpal commentedAny clean solution for this problem? I believe this is urgent.
Comment #36
constantinejohny CreditAttribution: constantinejohny commentedBig thanks for blueminds for #17, works perfectly!
Comment #37
Marty2081 CreditAttribution: Marty2081 commentedHmm, I created a custom token [node:summary-or-trimmed:300] that takes the number that is put in last as the length of the trimmed body last night. If the summary is empty, it will trim the body and return that. Too bad I did not see this thread before...
Comment #38
FiNeX CreditAttribution: FiNeX commented@Marty: would you like to share the code? I've planned to developed a token like your but for custom fields :-)
Comment #39
Marty2081 CreditAttribution: Marty2081 commented@FiNeX: sure. See below.
I'm not sure if everything I've done is the way it should be done, but it works for now. One thing that I'm uncertain of are if there is a better way to get the number of characters that the trimmed version of the body should be from dynamic part of the token (I'm now simply exploding the name of the token into an array).
Any improvement tips are welcome!
EDIT: removed the PHP syntax highlighting because that broke line 40...
EDIT: corrected wrong function name...
Comment #40
Danny EnglanderI created a module based on #39 above but had a few issues. There is a syntax error on line 40, should be:
preg_replace('/
. Beyond that I enabled the module, cleared my cache and input[node:summary-or-trimmed:300]
into the metatag Description field in a node but got the error when saving:The Description is using the following invalid tokens: [node:summary-or-trimmed:300].
. Not sure what else I might be doing wrong.Comment #41
Marty2081 CreditAttribution: Marty2081 commentedThe bug in line 40 is created by the input filter on drupal.org, because in the source the '/ is there. Do you see the token in the token list when you enable your module?
Comment #42
Danny Englander@Marty2081 - No I do not see the token when I enable the module. I am not sure what else I might be doing wrong. Thanks.
Comment #43
Jeordy CreditAttribution: Jeordy commentedAfter testing the Meta Description (manually filled or in use with tokens), i can say it's not working at all.
** edit
Edit the 'description' field and click 'Save' (for example a test sentence: this is the meta description). Then reopen the saved content and look at the 'description' field. It says [node:summary] again. When visiting the page, opening the source, there is no meta description at all.
Comment #44
coloryan CreditAttribution: coloryan commentedThat's odd, it's working for me on several sites.
Have you tried the core patch in #28?
Comment #45
L-four CreditAttribution: L-four commented@Jeordy are you using Display suite? because that sounds just like this issue http://drupal.org/node/1286148
Comment #46
Jeordy CreditAttribution: Jeordy commentedNo, i've installed the Metatag module on several sites, but none of them are showing the meta description in the source of the page.
The weird thing is, the description field just keeps turning back to [node:summary], even after pasting some text and saving the node. I've tested it on 5 sites, all with the same problem.
Comment #47
Das123 CreditAttribution: Das123 commentedJeordy, that is actually two separate issues that are unrelated. Had me confused for a while too. :)
Run the dev version of the module and that will solve the non-saving issue when editing nodes. Alpha 5 has a problem with displaying saved fields. The changes are saved but not displayed.
The Description meta tag not appearing is an issue with Drupal. See either #39 above or #28. Personally I like #39 because it leaves the core alone.
Comment #48
L-four CreditAttribution: L-four commented@Jeordy looks like your issue has been fixed on dev.
Fixed error with in metatag_metatags_load_multiple() that prevented data from being loaded.
Comment #49
Das123 CreditAttribution: Das123 commentedThe error in @Marty2081 #39 code is in line 5...
should be
There shouldn't be the word _base in the function. :)
Comment #50
Marty2081 CreditAttribution: Marty2081 commented@Das123: you're right. My module was named "gm_ base" so I forgot to take out "_base". I've updated the snippet above.
Comment #51
awasson CreditAttribution: awasson commented@Marty2081, thanks for the helper module... I've added it to a site today and it works like a charm! Hopefully the next snapshot of Metatag won't need it but for now, that is a solid solution and leaves the module un-hacked.
Cheers,
Andrew
Comment #52
Marty2081 CreditAttribution: Marty2081 commented@awasson: nice to know that it helped you. I don't know if this is a Metatag issue or a core / Token module issue since I would expect the token [node:summary] to work like my solution.
Comment #53
friendswoodtech CreditAttribution: friendswoodtech commented@blueminds - Thanks for your solution on this issue. I am attempting to implement and am not getting positive results.
http://falcon.friendswoodtech.com/node/4
I made the change in metatag.module, but still not rendering description if summary left blank. Not sure what I may have done wrong. Any clues???
Comment #54
Jeordy CreditAttribution: Jeordy commentedThnx guys/girls!!
Works great now!
Comment #55
voodootea CreditAttribution: voodootea commentedExcellent, works a charm! ... unless there is a line break in the body - HTML or plain text format, in which case only the first line is shown even if that is less than the number of characters specified in the token variable value.
Many thanks for your work on this guys :)
Comment #56
drupalcms.ir CreditAttribution: drupalcms.ir commentedon multilingual site just patch below codes on line 464 of metatag.module:
Comment #57
Slovak CreditAttribution: Slovak commentedUsing Metatag 7.x-1.0-alpha6 and patch from http://drupal.org/node/1300920#comment-6200094 gets the [node:summary] output and properly populated fields.
Comment #58
Jason Dean CreditAttribution: Jason Dean commented#39 is working great for me - thanks :)
I took this route because the core patch mentioned in #57 still looks like a work in progress (and technically is for D8 I think).
Comment #59
DamienMcKennaThis is completely dependent upon the core issue #1300920: The [node:summary] token does not output anything for body fields without a manual summary, if you need this functionality please use the patches from there and help reviewing that issue. For now I'm marking this as postponed.
Comment #60
DamienMcKennaMarked #1619408: Description not ouput if summary is not manually added instead of the timmed body as a duplicate.
Comment #61
MrPeanut CreditAttribution: MrPeanut commentedJust wanted to say that the solution from #39 worked perfectly for me. I also chose this route because, like pushka mentioned, this patch seems to be under active development.
Comment #62
dman CreditAttribution: dman commentedAs this is still open after a year, and I did a review of a recent site and found the issue was killing our rich snippets and open graph work we'd taken such care to put in, I've released a tiny fix-up module for anyone who needs it fixed NOW and doesn't want to hack core.
Node Summary Token
@ DamienMcKenna re bumping #1300920
- that's gone off onto D8-land, so it's a while away from being a usable fix for a stable D7 site released today... but I really don't know what's slowing it down. I see/understand no blockers in that queue.
I can +1 the importance there (will do) but it just looks a bit bogged down to me, coming in at this point.
Comment #63
DamienMcKenna@dman: thanks.
Now that at least part of that issue's problems have been shuffled off to another issue, the current patch can be tweaked accordingly and re-submitted. Hopefully we'll get this taken care of by the next stable release of Drupal.
Comment #64
Anonymous (not verified) CreditAttribution: Anonymous commented#62 module works for me.
Comment #65
mrmeech CreditAttribution: mrmeech commented#62 works for me, too. Thanks!
Comment #66
awasson CreditAttribution: awasson commentedJust wanted to thank dman for the mini-module described in #62. It works like a charm!
Comment #67
valthebaldHuge thanks to @dman for providing #62, indeed!
Does this issue belong to meta tag? I guess it's node_tokens() problem (summary field arrives empty), and should be handled in core.
Comment #68
DamienMcKenna@valthebald: The question comes up often enough that it's worth tracking the discussion here while #1300920: The [node:summary] token does not output anything for body fields without a manual summary is being worked on.
Comment #69
valthebald@DamienMcKenna: great, thanks for the link
Comment #70
capellicI applied the patch in #39. Thank you to @Marty2081 for doing the heavy lifting on this. I just want to point out that this, defining your own override in a custom module, is the best way of solving this problem for a couple of reasons:
Below is the code as I implemented it in my "Swiss Army Knife" module called "base."
Comment #71
onedotover CreditAttribution: onedotover commentedThanks for this code capellic!
Just a heads up if you are using this code: your field names might vary from the code above. Double check field_get_items($entity_type, $entity, $field_name) in the code above for your site setup. If you are using the default body field provided by node, it will be field_get_items('node', $node, 'body') not field_get_items('node', $node, 'field_body')
Comment #72
DamienMcKennaReducing this to a Normal issue as it's a bug in Drupal core.
Comment #73
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedUsing posts #70 and #71 worked for me.
Thank you !
Comment #74
Alauddin CreditAttribution: Alauddin commented#62 worked like a charm.
thank you @dman
For those who dont use git or not familiar with git, I am attaching the module here.
hope that helps
Comment #75
dman CreditAttribution: dman commentedSorry I didn't think to push this to a public project. I was hoping it wouldn't remain needed for long.
But I might as well bump it up to be easier to download.
Good idea to post this as an upload here Alauddin.
I've also bumped the project status so a download will become available there ... http://drupal.org/node/1911432
Comment #76
vitoabrusci CreditAttribution: vitoabrusci commentedusing [node:summary] with Meta tags 7.x-1.0-beta1, works correctly for me.
Comment #77
tfranz CreditAttribution: tfranz commented7.x-1.0-beta4 doesn't work for me.
#62 and #74 works – thank you!
Another approach:
http://drupal.org/project/fixcore (Display issues -> Empty summary token) works, for me, too.
Comment #78
DamienMcKennaHow about we not wait any further and provide a band-aid that can be removed once the core fix is committed?
Comment #79
DamienMcKennaA working patch.
Comment #80
DamienMcKennaI've committed the patch from #80, so the next release will have a working [node:summary] token. *happydance*
Comment #81
leanderl CreditAttribution: leanderl commentedhey @DamienMcKenna I'm joining you in the *happydance*! This issue has been driving me mad for about six months and I never quite got my head around it, because there are so many parts to it, at least in my mind. There is meta tag, og:tag, body summary, body trimmed, and meta tag module vs other solutions. I never pinpointed the problem in my haste to get things done and was forced to hack around in the projects I was working with.
But now with the current dev version (April 5) it just works out of the box. Just like I would wish in my dreams. Ergo: dreams can come true!
Let me buy you a beer or a beet juice in Portland!
Comment #82
DamienMcKenna@leanderl: I'm glad it's working well for you. I won't be at Drupalcon Portland this year, but I appreciate the sentiment :)
Comment #83
roeldl CreditAttribution: roeldl commentedI was just looking for this! thanks.
Comment #84
Jeremy B CreditAttribution: Jeremy B commentedPatch has added a file to my Drupal install, but still doesn't work. Is there anything else I have to do?
Comment #85
DamienMcKenna@ebpo: Clear your caches?
Comment #86
Jeremy B CreditAttribution: Jeremy B commented@DamienMcKenna : i made an account just for that. I feel ridiculous.
Comment #87
DamienMcKenna@ebpo: Welcome to drupal.org, we hope your stay will be comfortable :-)
Comment #88
DamienMcKenna1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.
Comment #88.0
DamienMcKennax