Monday, December 26, 2022
HomeWordPress Developmentphotos - get_the_post_thumbnail() title and alt attributes not displaying

photos – get_the_post_thumbnail() title and alt attributes not displaying


Seems this was brought on by the next customized theme filter in features.php. Commenting out mounted the issue.

perform image_alt_tags($content material) {
    world $submit;
    preg_match_all('/<img (.*?)/>/', $content material, $photos);
    if (!is_null($photos)) {
        foreach($photos[1] as $index => $worth) {
            if (!preg_match('/alt=/', $worth)) {
                $new_img = str_replace('<img', '<img alt="' . get_the_title() . '"', $photos[0][$index]);
                $content material = str_replace($photos[0][$index], $new_img, $content material);
            }
        }
    }
    return $content material;
}
add_filter('the_content', 'image_alt_tags', 99999);

add_filter('post_thumbnail_html', 'thumbnail_filter', 99, 5);

perform thumbnail_filter($html, $post_id, $post_thumbnail_id, $measurement, $attr) {
   // you may alter the resulted HTML right here
   $html = preg_replace(array('/alt=".*?"https://wordpress.stackexchange.com/", '/title=".*?"https://wordpress.stackexchange.com/"), '', $html);
   return $html;
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments