Вход | Регистрация | FAQ
Anonymous

Problems with ALT tags

+ Ответить

Сообщений: 3 Страница 1 из 1


Problems with ALT tags

sinophilia » Чт дек 21, 2017 7:38 am

We are facing a severe problem with our website, which is based on the WordPress theme Yamidoo Magazine. We tried to add ALT tags in the WordPress media library for our last blog post: http://socialmedia-blog.net/social-medi ... ich-china/. But even though they are filled, no ALT tags appear when I open the source code. My dev has tried to solve this problem by adding a plugin to populate the alt fields, but it didn't work. Do you have any idea how to solve this problem?

Best regards,
Stephan

Sinophilia Consulting Ltd.
Аватара пользователя

sinophilia

  • Сообщения: 1
  • Зарегистрирован: Чт дек 21, 2017 7:02 am

Re: Problems with ALT tags

webdevseopro » Пт дек 29, 2017 7:16 pm

Here is a WordPress snippet to put into your functions.php file to search your content for images which don't have an alt attribute. If they don't have an alt attribute this function will add it in with a default of the post title.

Код: Выделить всё
function add_alt_tags($content)
{
        global $post;
        preg_match_all('/<img (.*?)\/>/', $content, $images);
        if(!is_null($images))
        {
                foreach($images[1] as $index => $value)
                {
                        if(!preg_match('/alt=/', $value))
                        {
                                $new_img = str_replace('<img', '<img alt="'.$post->post_title.'"', $images[0][$index]);
                                $content = str_replace($images[0][$index], $new_img, $content);
                        }
                }
        }
        return $content;
}
add_filter('the_content', 'add_alt_tags', 99999);


Hope it helps

Regards

http://webdevseo.pro
Аватара пользователя

webdevseopro

  • Сообщения: 2
  • Зарегистрирован: Пт дек 29, 2017 6:54 pm
  • Откуда: UK

Re: Problems with ALT tags

Alireza-res » Вт янв 02, 2018 11:22 am

i think you should add alt tag when upload img in wordpress , it doesnt difficult
Аватара пользователя

Alireza-res

  • Сообщения: 3
  • Зарегистрирован: Пн окт 02, 2017 9:52 am


+ Ответить

Страница 1 из 1