• Resolved simonc17

    (@simonc17)


    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)
  • Add the following code snippet to remove the alt text from the img tags:

    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

    (@simonc17)

    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.

    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:

    [events_list view="grid" scope="future"]

    You can see the result here: https://mafw.org/test/alt-test/

    Thread Starter simonc17

    (@simonc17)

    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

    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/

    Maybe you could provide a link to your page.

    Thread Starter simonc17

    (@simonc17)

    Sure here’s the link: 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.

    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:

    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

    (@simonc17)

    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.phpon 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

    Do you still see those messages after removing my code snippet?

    Try changing the code snippet to this:

    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

    (@simonc17)

    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.