• I am working on improving accessibility for a website that uses your plugin. We have a custom template set up, though the photo field is simply set up with <?php $this->field->print_value() ?>

    I’m looking for a means that I might customize the tag so that I can add the participant’s firstname and lastname in “alt” text but cannot seem to find where I can specify this and/or hook into this. Can you point me in the right direction?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author xnau webdesign

    (@xnau)

    Yes, you can add alt text in the template like this:

    <?php $this->field->attributes['alt'] = "your alt text"; ?>

    of course, that has to be done before it is displayed.

    Thread Starter Matt Scheidler

    (@matt6303)

    Thanks for the reply.

    I am, however, trying to pull in the values for first_name and last_name, as defined elsewhere in the record, rather than a static “your alt text”. This is where I am having troubles.

    Here’s what I have come up with…it’s a multisite…but what I have been unable to figure out is how to pass through the person’s first name and last name, when I’m otherwise outputting the contents of the “photo” field.

    I didn’t build the original template so perhaps there’s a better way to iterate through the different fields.

    <?php if ($theField == 'photo') {
                ?>
                <div class="<?php echo $this->field->name ?>-field">
                    <span class="image-field-wrap basename pdb-image image-field-wrap display-mode-image">
                  <?php // $this->field->print_value() ?>
                  <?php 
                    $url = get_option( 'siteurl' );
                    $blogid = get_current_blog_id();
                        ?>
    
                <img src="<?php echo $url . '/wp-content/blogs.dir/' . $blogid . '/files/participants-database/' . $this->field->value ?>" alt="" />
                    </span>
                    
                </div>
    
                <?php } 
    Plugin Author xnau webdesign

    (@xnau)

    You have to do it the way I showed you, don’t try to build the HTML yourself.

    I just gave the code to add the alt attribute, you’ll need to figure out how to build the value to put in there.

    For instance, if you wanted it to be the first and last name, you could do something like this:

    <?php
    if ( $this->field->name === 'photo' ) {
      $alt_value = $this->record->values['first_name'] . ' ' . $this->record->values['last_name'];
      $this->field->attributes['alt'] = $alt_value;
    }
    ?>
    Thread Starter Matt Scheidler

    (@matt6303)

    I appreciate the additional information.

    The key for me was:
    $alt_value = $this->record->values['first_name'] . ' ' . $this->record->values['last_name'];

    That’s exactly what I was seeking. Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Alt text for photo’ is closed to new replies.