\WP_Stager_Integration\Event::get_main_image_alt(array $event): string

Description

Gets the main image alternative text from event media.

Falls back to the event title ($event[ 'name' ]) if no alt text is provided.

Parameters:

ParameterTypeDescription
$event array Raw Stager event data.

Returns:

string The main image alt text, or an empty string if no valid alt text was retrieved.

Information

Fileclass-event.php line 1384

Full Code

/**
 * Gets the main image alternative text from event media.
 *
 * Falls back to the event title (<code>$event[ 'name' ]</code>) if no alt text is provided.
 *
 * @param array  $event    Raw Stager event data.
 *
 * @return string   The main image alt text, or an empty string if no valid alt text was retrieved.
 */
public static function get_main_image_alt( $event ) {

    // Type casting
    $event = (array) $event;

    // Get data
    $media      = (array) ( $event[ 'media' ] ?? array());
    $main_image = (array) ( $media[ 'mainImage' ] ?? array() );
    $alt        = (string) ($main_image[ 'alternativeText' ] ?? $event[ 'name' ] ?? '');

    return $alt;
}

💡 If you ever get stuck or have a question, please check our FAQs, our Free Integration Service, our paid Full Integration Service, or reach out to us!

Get WP Stager Integration

🎁 Limited offer: Use code WELCOME26 to get your first month for free!