MODULENAME_page_attachment_alter() Undefined
First, there's a typo. It's not attachment, it's attachments.

Next, you can't simply call a function without defining it.

In Drupal hooks are used to modify existing code when it's being processed.

See hook_page_attachments_alter for an example of what you are supposed to do.

Using hooks, you simply define a new function prefixed with your module's machine name, put your code/alterations in there, and in the end it's automatically being hooked up for execution. No need to call it again.


function hook_page_attachments_alter(array &amp;$attachments) {

  // Conditionally remove an asset.
  if (in_array('core/jquery', $attachments['#attached']['library'])) {
    $index = array_search('core/jquery', $attachments['#attached']['library']);
    unset($attachments['#attached']['library'][$index]);
  }
}