Add alt to all images if missing with image file name

PHOTO EMBED

Sat Jul 06 2024 10:59:08 GMT+0000 (Coordinated Universal Time)

Saved by @ASPX #javascript #alt #alttoimages #seo

<script type="text/javascript" async>
    ////add Attrs alt to images	
	function addAltAttrs() {
			
    //get the images
    let images = document.querySelectorAll("img"); 
     
    //loop through all images
    for (let i = 0; i < images.length; i++) {
		
       //check if alt missing
       if  ( !images[i].alt || images[i].alt == "" || images[i].alt === "") {
		//add file name to alt
         images[i].alt = images[i].src.match(/.*\/([^/]+)\.([^?]+)/i)[1];
       }
    } 
    // end loop
}
</script>
content_copyCOPY

https://aspx.co.il/