OGP header.php のカスタマイズ
<!-- OGP --> <?php if (is_single() || is_page()) { ?> <?php while (have_posts()) : the_post(); ?> <meta property="og:title" content="<?php the_title(); ?>" /> <meta property="og:type" content="article" /> <?php if (get_post_meta($post->ID,'カスタムフィールド名',true)): ?> <meta property="og:image" content="<?php $fileid = get_post_meta($post->ID, カスタムフィールド名, false); $file = wp_get_attachment_image_src($fileid[0], 'full'); echo $file[0]; ?>" /> <?php elseif (has_post_thumbnail()): ?> <?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id, $size = 'thumbnail'); ?> <meta property="og:image" content="<?php echo $image_url[0]; ?>" /> <?php else: ?> <meta property="og:image" content="任意の画像URL" /> <?php endif; ?> <meta property="og:url" content="<?php the_permalink(); ?>" /> <?php endwhile; ?> <?php } elseif (is_home()) { ?> <meta property="og:title" content="<?php bloginfo('name'); ?>" /> <meta property="og:type" content="blog" /> <meta property="og:image" content="任意の画像URL" /> <meta property="og:url" content="<?php bloginfo('url'); ?>" /> <meta property="og:description" content="<?php bloginfo('description'); ?>" /> <?php } else { ?> <meta property="og:title" content="<?php wp_title('|', true, 'right'); ?><?php bloginfo('name'); ?>" /> <meta property="og:type" content="article" /> <meta property="og:image" content="任意の画像URL" /> <meta property="og:url" content="<?php echo get_bloginfo('url').$_SERVER['REQUEST_URI']; ?>" /> <meta property="og:description" content="<?php bloginfo('description'); ?>" /> <?php } ?> <!-- /OGP -->
OGP
og:typeウェブページが何のページであるか(必須)
例:blog,article,website
og:title
ウェブページの名前(必須)
og:image
ウェブページのサムネイル(必須)
og:url
ウェブページの URL(必須)
og:description
ウェブページの説明
og:site_name
サイト名
OGP画像シミュレータ
http://ogimage.tsmallfield.com/スポンサーリンク