AlT attribute for an image is helpful factor for SEO. But the plugin "Social Media Share Buttons" by Sygnoos is not adding alt attribute for all social images. The following is my approach to add alt attribute to the social images. For this reason, Bing search console is always give a warning message and refuse to index the site.
1. Find possible keyword using browser tool.
2. locate keyword using Visual Studio find feature. Location: /wp-content/plugins/social-media-builder/js/addNewSection/SGMBWidget.js
3. add alt attribute to the images with jQuery.
4. result:
Additionary, to set all images ALT value where alt is missing, using this script:
Set alt value to image file name where alt is missing
$('img').each(function(i,e){
if($(e).attr('alt')=='')
$(e).attr('alt', $(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,''));
});
How to get this script? Explained below.
//show all img src
$('img').each(function(i,e){console.log($(e).attr('src'));});
//show all img alt
$('img').each(function(i,e){console.log($(e).attr('alt'));});
//get file name from path
filepath.replace(/^.*(\\|\/|\:)/, '');
//get file name without extension from file name
filename.replace(/\.[^/.]+$/,'');
//show all img file name without extension
$('img').each(function(i,e){console.log($(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,''));});
//set alt value to image file name where alt is missing
$('img').each(function(i,e){if($(e).attr('alt')=='') $(e).attr('alt', $(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,''));});
Comments