この記事では、記事ごとに著者情報の他に記事の監修者を表示するカスタマイズをご紹介します。
この記事を実践すると以下のようなイメージで記事の監修者を表示できます👇

子テーマのfunctions.phpに以下のような記述をします!
PHP
<?php
add_filter('sng_author_info', 'override_author_info', 10, 3);
function override_author_info($html, $options) { global $post; $supervisor_id = get_post_meta($post->ID, 'post_supervisor', true); if (!$supervisor_id) { return $html; } return $html . sng_author_info_by_id($supervisor_id, '記事の監修者');
}
add_action('sng_field_side_extra', function () { global $post; $meta_value = get_post_meta($post->ID, 'post_supervisor', true); ob_start(); $users = get_users(); foreach ($users as $user) { $selected = $user->ID === $meta_value ? " selected" : ""; ?> <option value="<?php echo $user->ID ?>"<?php echo $selected ?>><?php echo $user->display_name ?></option> <?php } $options = ob_get_clean(); echo '<p class="sng-field-title"><img draggable="false" role="img" class="emoji" alt="👦" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f9d1-200d-1f4bb.svg"> 監修者名</p>'; echo "<div style='margin-top: 10px;'> <select name='post_supervisor'> <option value=''>監修者を選択</option> $options </select> </div>";
});
add_action('sng_update_custom_fields', function ($post_id) { sng_update_custom_text_fields($post_id, 'post_supervisor');
}, 10, 3);
各記事ページで、監修者を選択します。

コメントを残す