Wrong logic in noindex_metatag_page_attachments

Created on 21 April 2025, 13 days ago

Problem/Motivation

It is wrong logic in noindex_metatag_page_attachments (noindex_metatag.module):

foreach ($val as $meta) {
              if (isset($meta['#attributes']['name']) && ($meta['#attributes']['name'] == 'robots')) {
                $attachments['#attached']['html_head'][$key][0]['#attributes']['content'] = 'noindex';
              }
              else {
                $robots = [
                  '#tag' => 'meta',
                  '#attributes' => [
                    'name' => 'robots',
                    'content' => 'noindex',
                  ],
                ];
                $attachments['#attached']['html_head'][] = [$robots, 'robots'];
              }
            }

Everytime when logic isset($meta['#attributes']['name']) && ($meta['#attributes']['name'] == 'robots') false you add new meta-tag. But it should be done only once after you check all array $attachments['#attached']['html_head'].

Proposed resolution

It is better to use flag to fix and reduce the code.

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024