How to hide Alt and Title fields for anonymus users when they upload images? I use tokens for these field that's why I need to hide them.


Here a solution for hide the alt and title fields:

 * Implements hook_field_widget_form_alter().
function MYMODULE_field_widget_form_alter(&$element, &$form_state, $context) {
    // If this is an image field type
    if ('image' === $context['field']['type'] && 'MY_FIELD' === $context['instance']['bundle']) {
    // Loop through the element children (there will always be at least one).
    foreach (element_children($element) as $key => $child) {
        // Add the new process function to the element
        $element[$key]['#process'][] = 'MYMODULE_image_field_widget_process';

function MYMODULE_image_field_widget_process($element, &$form_state, $form) {
    $element['title']['#access'] = FALSE;
    $element['alt']['#access'] = FALSE;

    // Return the altered element
    return $element;

Et voila :)

| improve this answer | |

This could work with Field Permissions module...

| improve this answer | |
  • I tried it but it doesn't control Alt and Title attributes. Only create/edit/delete actions :( – moto Nov 18 '12 at 20:04
  • Sorry, my answer was way too hastily... you're right, it's not working this way. – Volker Nov 19 '12 at 13:14

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.