2022年04月25日

WP関数:get_uploaded_header_images()

この関数の説明

WP関数の get_uploaded_header_images() は、[外観→カスタマイズ]の[ヘッダ画像]の中に登録した画像を連想配列で取り出す関数です。

※ヘッダ画像をスライドさせる場合は、この関数を使います。

 


関数

get_uploaded_header_images()

 


オプション

ありません

 


返り値

連想配列で、画像情報が返されます。

下記は、2つの画像が設定された事例です。

Array
(
    [4344] => Array
        (
            [attachment_id] => 4344
            [url] => https://hnw.t-spirits.com/school/wp-content/uploads/2020/12/cropped-86-3.jpg
            [thumbnail_url] => https://hnw.t-spirits.com/school/wp-content/uploads/2020/12/cropped-86-3.jpg
            [alt_text] => 
            [attachment_parent] => 444
            [width] => 959
            [height] => 323
        )

    [4346] => Array
        (
            [attachment_id] => 4346
            [url] => https://hnw.t-spirits.com/school/wp-content/uploads/2020/12/cropped-crown.jpg
            [thumbnail_url] => https://hnw.t-spirits.com/school/wp-content/uploads/2020/12/cropped-crown.jpg
            [alt_text] => 
            [attachment_parent] => 451
            [width] => 905
            [height] => 300
        )

)

上記で重要なキーは下記になります。

キー 内容
'url' イメージのURL
'thumbnail_url' サムネールイメージのURL(URLと同一)

 


事例

①ヘッダー画像が登録されていたら画像を表示します。

<?php if(has_header_image()):?><!-- ヘッダ画像が設定されている場合 -->
	<div id='top_slide'>
		<?php foreach (get_uploaded_header_images() as $key => $value): ?>
			<img src='<?php echo esc_url($value['url']);?> 'width="100%">
		<?php endforeach;?>
	</div>
<?php endif;?>

■画像のURLはURLをエスケープ処理をしてから表示しています。

 


関連情報

関連関数は テーマのカスタマイズ関連関数 を参照してください。

 

関数一覧
  • 1.WPのエスケープ処理
  • 2.WPプログラムの基本
  • 3.ヘッダ/フッタ/サイドバで使われる関数
  • 4.DBからの読込関数
  • 5.一般テンプレートの中で使われる関数
  • 6.その他のWP関数
  • add_shortcode()
  • bloginfo()
  • body_class()
  • date_i18n()
  • dynamic_sidebar()
  • edit_post_link()
  • esc_attr()
  • esc_html_e()
  • esc_html()
  • esc_url()
  • get_ancestors()
  • get_cat_ID()
  • get_cat_name()
  • get_category_link()
  • get_category_parents()
  • get_category()
  • get_footer()
  • get_header()
  • get_home_url()
  • get_post_format()
  • get_post_meta()
  • get_post_thumbnail_id()
  • get_query_var()
  • get_search_query()
  • get_sidebar()
  • get_site_url()
  • get_stylesheet_directory_uri()
  • get_stylesheet_uri()
  • get_template_directory_uri()
  • get_template_part()
  • get_the_category()
  • get_the_content()
  • get_the_date()
  • get_the_excerpt()
  • get_the_ID()
  • get_the_modified_date()
  • get_the_modified_time()
  • get_the_permalink()
  • get_the_post_thumbnail()
  • get_the_tags()
  • get_the_time()
  • get_the_title()
  • get_uploaded_header_images()
  • get_year_link()
  • has_category()
  • has_custom_logo()
  • has_header_image()
  • has_header_video()
  • has_nav_menu()
  • has_post_thumbnail()
  • has_tag()
  • header_image()
  • home_url()
  • is_admin()
  • is_category()
  • is_date()
  • is_front_page()
  • is_home()
  • is_main_query()
  • is_page()
  • is_search()
  • is_single()
  • language_attributes()
  • the_category()
  • the_content()
  • the_custom_header_markup()
  • the_custom_logo()
  • the_date()
  • the_excerpt()
  • the_ID()
  • the_modified_date()
  • the_modified_time()
  • the_permalink()
  • the_post_thumbnail()
  • the_search_query()
  • the_tags()
  • the_time()
  • the_title()
  • update_post_meta()
  • wp_get_attachment_image_src()
  • wp_nav_menu()
  • WP_Query()