Title: EM automatically adding alt text
Last modified: February 16, 2025

---

# EM automatically adding alt text

 *  Resolved [simonc17](https://wordpress.org/support/users/simonc17/)
 * (@simonc17)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/)
 * None of my images have alt text defined as they are decorative yet EM is automatically
   adding alt text to the image using the image’s title. This is not right and it
   shouldn’t do it. If there is no alt text defined for the image, EM should to 
   meet accessibility standards and ensure that the image is not announced by a 
   screenreader add alt=”” into the image’s HTML.
 * There seems to be no setting to turn this off so does anyone know if this is 
   solveable via a simple function?
 * Thanks.

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18309620)
 * Add the following code snippet to remove the alt text from the img tags:
 *     ```wp-block-code
       add_filter('em_event_output_placeholder', function( $replace, $EM_Event, $result ) {    if ( preg_match( '/#_EVENTIMAGE.*/', $result ) ) {        $replace = preg_replace( "/alt='[^']*'/", "", $replace );    }    return $replace;}, 100, 3);add_filter('em_location_output_placeholder', function( $replace, $EM_Location, $result ) {    if ( preg_match( '/#_LOCATIONIMAGE.*/', $result ) ) {        $replace = preg_replace( "/alt='[^']*'/", "", $replace );    }    return $replace;}, 100, 3);add_filter('em_taxonomy_placeholder', function( $replace, $taxonomy, $result ) {    if ( preg_match( '/#_TAXONOMYIMAGE.*/', $result ) ) {        $replace = preg_replace( "/alt='[^']*'/", "", $replace );    }    return $replace;}, 100, 3);
       ```
   
 *  Thread Starter [simonc17](https://wordpress.org/support/users/simonc17/)
 * (@simonc17)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18310342)
 * Hi,
 * Thanks again for helping. Unfortunately this doesn’t work. I am using the following
   shortcode to generate an events grid and the alt tags are not being removed from
   the images (I’ve purged all caches): [events_list view=”grid” scope=”future”]
 * Thanks.
 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18310634)
 * That’s strange because I tested my code snippet and it did remove all the alt
   text from the img tags. I also verified it works when using the following shortcode:
 *     ```wp-block-code
       [events_list view="grid" scope="future"]
       ```
   
 * You can see the result here: [https://mafw.org/test/alt-test/](https://mafw.org/test/alt-test/)
 *  Thread Starter [simonc17](https://wordpress.org/support/users/simonc17/)
 * (@simonc17)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18310865)
 * I uploaded an image and set it to have its own alt text. Inspecting the page 
   EM wasn’t using this, it was just taking the title of the event and using that
   for the alt text. That’s bad as it should use the image’s alt text.
 * Looking at the preg_replace line, I’m trying to understand if you are replacing
   just the text within the “” of the alt=”text here” definition or are simply replacing
   everything after alt=. I’m not a coder and all the ” and ‘ are a little confusing.
   I’m guessing you are replacing what is within the “” which is weird why it isn’t
   working.
 * Thanks
 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18311034)
 * I’m removing the alt=”text here”
 * And it does work as you can see on my test page: [https://mafw.org/test/alt-test/](https://mafw.org/test/alt-test/)
 * Maybe you could provide a link to your page.
 *  Thread Starter [simonc17](https://wordpress.org/support/users/simonc17/)
 * (@simonc17)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18311063)
 * Sure here’s the link: [https://ottervalechurches.org/](https://ottervalechurches.org/)
 * Check any of the event card images and you’ll see alt text. None of these have
   alt text defined for the image in Media.
 * Thanks again.
 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18311426)
 * Maybe the code snippet is not being run on your site. Edit the wp-config.php 
   in the top directory of your WordPress site and check if WP_DEBUG, WP_DEBUJG_LOG,
   WP_DEBUG_DISPLAY is already defined replace it with the following lines (or add
   these lines if they are not already defined):
 * define( ‘WP_DEBUG’, true );
   define( ‘WP_DEBUG_LOG’, true );define( ‘WP_DEBUG_DISPLAY’,
   true );
 * Then change my code snippet to this:
 *     ```wp-block-code
       add_filter('em_event_output_placeholder', function( $replace, $EM_Event, $result ) {    if ( preg_match( '/#_EVENTIMAGE.*/', $result ) ) {        error_log("Doing the replace");        $replace = preg_replace( "/alt='[^']*'/", "", $replace );    }    return $replace;}, 100, 3);add_filter('em_location_output_placeholder', function( $replace, $EM_Location, $result ) {    if ( preg_match( '/#_LOCATIONIMAGE.*/', $result ) ) {        $replace = preg_replace( "/alt='[^']*'/", "", $replace );    }    return $replace;}, 100, 3);add_filter('em_taxonomy_placeholder', function( $replace, $taxonomy, $result ) {    if ( preg_match( '/#_TAXONOMYIMAGE.*/', $result ) ) {        $replace = preg_replace( "/alt='[^']*'/", "", $replace );    }    return $replace;}, 100, 3);Expand
       ```
   
 * Then check the error.log file to see if the message appears in the file. The “
   Doing the replace” message should also show up on your web page.
 *  Thread Starter [simonc17](https://wordpress.org/support/users/simonc17/)
 * (@simonc17)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18313015)
 * Hi,
 * I’ve done this and on the web page get this displayed:
 * **Deprecated**: preg_match(): Passing null to parameter #2 ($subject) of type
   string is deprecated in **/home/otterval/staging.ottervalechurches.org/wp-content/
   plugins/events-manager/classes/em-object.php**on line **1407**
 * In the debug log I get loads of these:
 * [18-Feb-2025 10:39:04 UTC] PHP Deprecated: preg_match(): Passing null to parameter#
   2 ($subject) of type string is deprecated in /home/otterval/staging.ottervalechurches.
   org/wp-content/plugins/events-manager/classes/em-object.php on line 1407 [18-
   Feb-2025 10:39:04 UTC] Doing the replace
 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18313487)
 * Do you still see those messages after removing my code snippet?
 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18313518)
 * Try changing the code snippet to this:
 *     ```wp-block-code
       add_filter('em_event_output_placeholder', function( $replace, $EM_Event, $result ) {    if ( !empty( $result ) && preg_match( '/#_EVENTIMAGE.*/', $result ) ) {        $replace = preg_replace( '/alt="[^"]*"/', "", $replace );    }    return $replace;}, 100, 3);add_filter('em_location_output_placeholder', function( $replace, $EM_Location, $result ) {    if ( !empty( $result ) && preg_match( '/#_LOCATIONIMAGE.*/', $result ) ) {        $replace = preg_replace( '/alt="[^"]*"/', "", $replace );    }    return $replace;}, 100, 3);add_filter('em_taxonomy_placeholder', function( $replace, $taxonomy, $result ) {    if ( !empty( $result ) && preg_match( '/#_TAXONOMYIMAGE.*/', $result ) ) {        $replace = preg_replace( '/alt="[^"]*"/', "", $replace );    }    return $replace;}, 100, 3);
       ```
   
 *  Thread Starter [simonc17](https://wordpress.org/support/users/simonc17/)
 * (@simonc17)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18313697)
 * Bingo, that one worked.
 * Again, thanks for all your help.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘EM automatically adding alt text’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 11 replies
 * 2 participants
 * Last reply from: [simonc17](https://wordpress.org/support/users/simonc17/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/em-automatically-adding-alt-text/#post-18313697)
 * Status: resolved