• I’ve done this manually myself by editing the item.php file, but it would be great if the alt tag was filled in like the title tag. You can go one step further and shorten the length of the alt (and title) tag by truncating the output to a set number of characters if the title is longer than X characters.

    Cheers

Viewing 1 replies (of 1 total)
  • Thread Starter GregW

    (@gwmbox)

    My edits

    in item.php change it to add content to the alt tag AND limit the number of characters as often instagram titles can be very long

    <li class="wpmi-item"><a href="<?php echo esc_attr( $item['url'] );?>" target="<?php echo esc_attr( $args['target'] );?>"><img src="<?php echo esc_url( $item[$args['size']] );?>" alt="<?php echo myTruncate(esc_attr( $item['description'] ), 125, " ");?>" title="<?php echo esc_attr( $item['description'] );?>"/></a></li>

    Change where it says 125 to whatever character length you want. From what I have read 125 characters is the sweet spot for an alt tag length

    in your functions.php file, add;

    // Lets shorten (truncate) text as needed
    
    function myTruncate($string, $limit, $break=".", $pad="...")
    {
      // return with no change if string is shorter than $limit
      if(strlen($string) <= $limit) return $string;
      // is $break present between $limit and the end of the string?
      if(false !== ($breakpoint = strpos($string, $break, $limit))) {
        if($breakpoint < strlen($string) - 1) {
          $string = substr($string, 0, $breakpoint) . $pad;
        }
      }
      return $string;
    }

    Cheers

Viewing 1 replies (of 1 total)
  • The topic ‘Request – Alt tags Filled’ is closed to new replies.