~ 1 min read

Alter WYSIWYG settings in Drupal

share this story on
Altering WYSIWYG settings to make image URLs absolute so that they are also accessible via Email clients.

If you deliver content notifications over email and that content may have images attached to it, inline in the message, it will badly display an image source that it can’t find. This is because when the WYSIWYG adds the image to the page it sets the image source to be a relative URL such as /system/files/image_1.jpg.

It’s possible to create an alter hook that changes the init settings passed to the WYSIWYG and making every attached image as a full http:// source link.

/**
 * Implements hook_wysiwyg_editor_settings_alter
 * Alters the WYSIWYG editor settings to make URLs for images be absolute (i.e: prefixed with http://)
 * so that they are also accessible via Email clients.
 */
function my_module_wysiwyg_editor_settings_alter($settings, $context) {
 $settings['convert_urls'] = TRUE;
 $settings['relative_urls'] = FALSE;
 $settings['remove_script_host'] = FALSE;
}