WordPressでAuthorの構造化データを出力する実装サンプル
最終更新日時 : 2026.08.26
WordPressで記事の執筆者ユーザー情報を取得して、構造化データ(Author)として出力する実装サンプルです。
①Advance Custom Fieldに執筆者情報を追加

プラグイン「Advanced Custom Fields」をインストール後、上図のようにユーザータイプの執筆者項目を投稿に対して設定します。
②functions.phpにアクションフックを追加
function my_meta_ogp()
{
global $post;
$title = "";
$description = "";
$url = "";
$html = "";
$title = get_bloginfo('name');
$description = "デフォルトの紹介文";
$url = home_url();
if (is_single() || is_page()) {
setup_postdata($post);
$title = $post->post_title;
$description = strip_shortcodes($post->post_content);
$description = wp_html_excerpt($description, 100, '…');
$url = get_permalink();
$writerId = get_field('writer', $post->id);
$writerInfo = get_userdata($writerId);
$writerAvatar = get_avatar_data($writerId);
$writer_first_name = $writerInfo->first_name;
$writer_last_name = $writerInfo->last_name;
$writer_description = $writerInfo->description;
$writer_url = $writerInfo->url;
$writer_image_url = $writerAvatar["url"];
if(!empty($writerInfo)):
$html .= '<script type="application/ld+json">';
$html .= '{';
$html .= '"@context": "https://schema.org",';
$html .= '"@type": "Article",';
$html .= '"mainEntityOfPage": "' . esc_url($url) . '",';
$html .= '"headline": "' . esc_attr($title) . '",';
$html .= '"description": "' . $description . '",';
$html .= '"author": [{';
$html .= '"@type": "Person",';
$html .= '"name": "' . $writer_last_name . ' ' . $writer_first_name . '",';
$html .= '"url": "' . $writer_url . '",';
$html .= '}]';
$html .= '}';
$html .= '</script>';
endif;
wp_reset_postdata();
}
echo $html;
}
add_action('wp_head', 'my_meta_ogp');
投稿者プロフィール
- 代表者
-
東海大学工学部を卒業後、東芝情報システム株式会社(旧グループ会社含む)に入社。半導体(SRAM)の開発チームにて、Unix環境でのPerlを用いた業務自動化プログラムの開発など、エンジニアとしての確かな基礎と緻密な論理的思考力を培う。
その後、東証上場企業である株式会社ザッパラスへ。Web・モバイルの最前線で、数多くのユーザーに愛されるコンテンツ制作業務に従事。ここで「ユーザー目線に立った魅力的なWebコンテンツの企画・制作ノウハウ」を深く学ぶ。
開発・システム側から見た「堅牢なロジック」と、制作・ユーザー側から見た「伝わるコンテンツ」の双方を実務で経験した強みを活かし、フリーランスとして独立。
現在は、ウイングアーク1st株式会社の「データのじかん」運営チームに参画するなど、大手・中小企業のWeb運営・開発パートナーとして活動。完全在宅でありながら、固定IPの完備や厳格なセキュリティポリシーの遵守を徹底し、企業のインフラや本番環境を安全に支える「チームの一員」として高い信頼を得ています。
見た目の美しさはもちろんのこと、内部の構造やWordPressのカスタマイズ、運用・セキュリティまでを見据えた、技術的バックボーンのある高品質なWebサイト・システム制作をワンストップでご提供しています。

