ALT Attribute in articles isn't filled correctly

Home Forums Reykjavik ALT Attribute in articles isn't filled correctly

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #21429

    wuesl
    Participant

    ALT Attribute in articles isn't filled correctly

    Resolved

    Hey there! Have you noticed this support service is provided FREE of charge?
    If you like the speed and accuracy of resolutions, please consider supporting me with a small donation. Thank you

    Consider a donation →

    Hello Oliver,

    Look my added graphic files. The ALT attribute in articles isn’t filled correctly. As you can see it is filled with the title of the whole webpage.

    Would it be possible that you can give me workaround tip until you revise the theme?

    As for us we do need really high performance in accessibility to our website.

    Thank you in advance
    Ulrich

    #21430

    Oliver Juhas
    Keymaster

    Hi Ulrich,

    You mean the alt attribute content of intro section images, I think.

    Please note that there is a problem with WordPress itself. I have reported the issue some time ago at https://core.trac.wordpress.org/ticket/46124

    The fix via a theme would be quite large and really counterproductive as this needs to be fixed in WP core.

    It is currently not possible to get the actual image alt text you set in your WordPress media library. However, probably best approach now would be to set an empty alt attribute as the custom header (intro) image is considered a decorative image. This can be done via your child theme functions.php file:

    function child_theme_get_header_image_tag( $html, $header, $attr ) {
    	$attr['alt'] = ''; // Setting empty alt for custom header images - they are decorative.
    	$html = '<img';
    	foreach ( $attr as $name => $value ) {
    		$html .= ' ' . $name . '="' . esc_attr( $value ) . '"';
    	}
    	$html .= ' />';
    	return $html;
    }
    add_filter( 'get_header_image_tag', 'child_theme_get_header_image_tag', 10, 3 );

    Best regards,

    Oliver Juhas
    WebMan Design

    #21433

    wuesl
    Participant

    Hi Oliver,

    I meant the ALT attribute of pictures of articles. I.e. when use the Theme Twenty fifteen the ALT attribute of the picture in the post itself is set correctly.

    Greetings
    Ulrich

    #21440

    Oliver Juhas
    Keymaster

    Hi Ulrich,

    Please understand that each theme is different. Twenty Fifteen seems to be using a different approach simply :) But there’s nothing wrong about Reykjavik’s approach, it actually uses WordPress native functions to display the image. It’s pity there is a bug in WordPress regarding this.

    To resolve your issue you can try this:

    1. Copy the templates/parts/intro/intro-media.php file into your child theme keeping the folder structure.
    2. Edit the file in your child theme and change the <?php the_custom_header_markup(); ?> line (#36) to:
      	<?php
      
      	if ( is_singular() && has_post_thumbnail( get_the_ID() ) ) {
      		echo '<div id="wp-custom-header" class="wp-custom-header o">';
      		the_post_thumbnail( 'reykjavik-intro' );
      		echo '</div>';
      	} else {
      		the_custom_header_markup();
      	}
      
      	?>

    That should help.

    Best regards,

    Oliver Juhas
    WebMan Design

    #21463

    wuesl
    Participant

    Hi Oliver,

    Thank you very much for your research. I will try your work around and hope that the WordPress core team will consider to resolve this issue within the next release.

    In most cases when you have header image of course this is a decorative image. But we are using images mainly a.s. the Header image of posts. In this case it is necessary for us to add a meaningful old text attribute.

    Thanks
    Ulrich

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.