Astra_Ext_Advanced_Headers_Markup::get_header_background_image_alt_text()

Get Page Header Image Alt Text


Description


Return

(string) Alt text if provided for the image else post/archive title.


Source

File: addons/advanced-headers/classes/class-astra-ext-advanced-headers-markup.php

		public function get_header_background_image_alt_text() {
			$page_post_featured = Astra_Ext_Advanced_Headers_Loader::astra_advanced_headers_design_option( 'page-post-featured' );
			$bg_image           = Astra_Ext_Advanced_Headers_Loader::astra_advanced_headers_design_option( 'bg-image' );

			// If advanced header disabled.
			$title_bar_bg_img = '';

			if ( ( is_archive() || is_search() || is_404() || is_home() ) && $bg_image ) {
				$title_bar_bg_img = $bg_image;
			} else {
				// If selected Post / Page Featured image.
				if ( 'enabled' == $page_post_featured ) {

					if ( has_post_thumbnail( get_the_ID() ) ) {
							$src              = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'thumbnail_size' );
							$title_bar_bg_img = $src[0];
					} else {
						// Custom Background Image.
						if ( $bg_image ) {
							$title_bar_bg_img = $bg_image;
						}
					}
				} else {
					// Custom Background Image.
					if ( $bg_image ) {
						$title_bar_bg_img = $bg_image;
					}
				}
			}

			$img_alt_text = get_post_meta( attachment_url_to_postid( $title_bar_bg_img ), '_wp_attachment_image_alt', true );

			if ( ! empty( $img_alt_text ) ) {
				return 'aria-label="' . esc_attr( $img_alt_text ) . '"';
			}
			return __return_empty_string();
		}

Changelog

Changelog
Version Description
2.2.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.