【ACF】ユーザープロフィール写真とは別の画像を登録する方法

Advanced Custom Fieldsでユーザープロフィール写真とは別の画像を登録し、
サイトに表示する方法をご紹介します。
Advanced Custom Fieldsでフィールドを追加する
・フィールドラベル :ユーザーアイコン とします(任意)
・フィールド名 :user-icon とします(任意)
・フィールドタイプ :「画像」を選択
・返り値のフォーマット:「画像 URL」にチェックを入れます
・位置のルール :ユーザーフォームと等しい とします

プロフィール編集ページにフィールドが追加されていることを確認
デフォルトの「プロフィール写真」とは別に、
画像を登録できる「ユーザーアイコン」という項目が追加されました。

画像を登録します。

フッターに画像付きユーザー一覧リストを表示する
ユーザーアイコン画像の下にユーザー名が表示されるユーザー一覧を実装します。

サンプルコード
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $users = get_users( array( 'orderby'=>ID, 'order'=>ASC ) ); ?> <ul class="author_list"> <?php foreach($users as $user) { $uid = $user->ID; ?> <li> <div class="author_thumb01"> <a href="<?php echo get_bloginfo("url") . '/?author=' . $uid ?>"> <img src="<?php the_field('user-icon', 'user_'. $uid ); ?>" /> </a> </div> <p class="author_name01"><?php echo $user->display_name ; ?></p> </li> <?php } ?> </ul> |
ユーザー別記事詳細ページ(author.php)にユーザーアイコンを表示する

サンプルコード
|
1 2 3 4 5 6 7 8 |
<?php $uid = get_the_author_meta(ID, $author); ?> <dl class="author_title_dl"> <dt><img src="<?php the_field('user-icon', 'user_'. $uid ); ?>" /></dt> <dd><span><?php the_author_nickname(); ?></span> の記事一覧</dd> </dl> <div class="author_description"><?php echo wpautop(get_the_author_meta('user_description')); ?></div> |
記事詳細ページ(single.php)にユーザーアイコンを表示する

|
1 2 3 4 5 6 7 8 9 10 11 |
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $uid = get_the_author_meta(ID, $userID); ?> <div class="clearfix"> <h2 class="post_title"><?php the_title(); ?></h2> <div class="author_bl"> <img src="<?php the_field('user-icon', 'user_'. $uid ); ?>" /> <span><?php the_author_meta( 'nickname' ); ?></span> </div> </div> |
|
1 2 3 |
<?php $uid = get_the_author_meta(ID, $userID); ?> |
はループ内に書かないと画像が表示されないので注意
![MARKLEAPS[マークリープス]](https://markleaps.com/blog/wp-content/themes/mkl/images/00_logo.png)

![[WordPress] プラグイン「WP ALL Import」で既存記事を一括更新(CSV上書き)する方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import_update-500x254.jpg)
![[WordPress] CSVで記事を一括インポート-プラグイン「WP ALL Import」の使い方](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import-500x254.jpg)
![[WordPress] 記事への画像挿入方法](https://markleaps.com/blog/wp-content/uploads/2025/10/pic_manual_mainimg-500x254.png)
![[WordPress] カテゴリーとタグの違いと設定方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-category-tag-500x254.jpg)