2

We are using metatag v8.x-1.5 on our D8 site (v8.5.3). When filling out the metatag description field, we enter any where from 180-320 characters into the field. However, when the page is displayed it is cutting off after 135 characters.

How can we increase the number of characters that are displayed?

Steps to reproduce:

  1. Enter "Compellingly re-engineer bleeding-edge interfaces whereas interoperable quality vectors. Uniquely incubate one-to-one action items before best-of-breed catalysts for change. Interactively." into the Metatag Description field. metatag description

Current behavior:

<meta name="description" content="Compellingly re-engineer bleeding-edge interfaces whereas interoperable quality vectors">

Expected behavior:

<meta name="description" content="Compellingly re-engineer bleeding-edge interfaces whereas interoperable quality vectors. Uniquely incubate one-to-one action items before best-of-breed catalysts for change. Interactively.">

  • This sounds like either a module bug or a core bug. I would check the module issue queue and ask there (especially since the help text states 320 characters). – Kevin May 19 '18 at 13:55
  • @Kevin I see a feature request to add a configuration setting for the description length. I might have to write a mymodule_page_attachments_alter hook if i cannot find anything else. – usernameabc May 21 '18 at 17:27
1

I had to write a hook_page_attachments_alter for this

function mymodule_page_attachments_alter(array &$page) {
  foreach($page['#attached']['html_head] as &$html_head) {
    if($html_head[1] == 'description') {
      $html_head_content = $html_head[0]['#attributes']['content'];
      if(Unicode::strlen($html_head_content) > 320) {
        $html_head[0]['#attributes']['content'] = Unicode::truncate($html_head_content, 320);
      }
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.