Quantcast
Channel: プラグイン検証用-FTPup
Viewing all articles
Browse latest Browse all 88

OGPイメージを出力する

$
0
0

 

head.php

<meta property='og:title' content='<?php the_title() ?>'>
<meta property='og:url' content='<?php the_permalink() ?>'>
<meta property="og:image" content="<?php echo catch_that_image(); ?>">

functions.php

function catch_that_image() {
 global $post, $posts;
 $first_img = home_url() . '/default.png';
 ob_start();
 ob_end_clean();
 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
 $first_img = $matches [1] [0];
 
 return str_replace( '[my_home_url]', home_url(), $first_img );
}

※サイトの直下にデフォルト画像を配置


Viewing all articles
Browse latest Browse all 88

Trending Articles