Alt Text for Images and Deleting old images

Home Forums Calendar Products Events Calendar PRO Alt Text for Images and Deleting old images

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1325672
    James
    Participant

    I have noticed that when I used the Events Aggregator, the images which are pulled from other place into the website have no Alt Text, or Captions with them. Can this have some default settings so it mirrors the title of the event?

    ALSO, when events are over, Is there an easy way to delete all of the left left over events, AND more importantly, space grabbing graphics?

    #1326643
    Barry
    Member

    Hi James,

    What might make more sense here (rather than target Event Aggregator specifically) is an approach that provides default attributes when necessary for featured event images generally.

    The tribe_event_featured_image hook provides an opportunity to do this:

    add_filter( 'tribe_event_featured_image', function( $html, $event_id ) {
    	$img_start = strpos( $html, '<img ' );
    	$img_end   = strpos( $html, '/>', $img_start );
    	$img_len   = $img_end + 2 - $img_start;
    
    	if ( ! $img_start || ! $img_end ) {
    		return $html;
    	}
    
    	$img = substr( $html, $img_start, $img_len );
    
    	// Add an alt tag if it does not already have one
    	if ( false !== strpos( $img, 'alt="' ) ) {
    		$title = esc_attr( get_the_title( $event_id ) );
    		$img   = substr_replace( $img, 'alt="' . $title . '" ', 5, 0 );
    		$html  = substr_replace( $html, $img, $img_start, $img_len );
    	}
    
    	return $html;
    }, 10, 2 );

    The above shows one way of doing this that doesn’t assume any additional PHP extensions are installed and adds an alt tag if it is missing.

    Adding captions or title attributes (for native ‘tooltips’) could be implemented using a similar approach. Does this help – or at least give you a starting point – with the first part of your question?

    #1336891
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Alt Text for Images and Deleting old images’ is closed to new replies.