Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/d385621bf39c75e10116 to your computer and use it in GitHub Desktop.
Save kurozumi/d385621bf39c75e10116 to your computer and use it in GitHub Desktop.
【ワードプレス】qiitaの記事を自動メディアリンクに対応させる方法
wp_embed_register_handler(
'qiita',
'#http://qiita.com/(.*)/items/([a-z0-9]+)$#i',
function($m, $attr, $url, $rawattr){
$url = sprintf("http://qiita.com/api/v2/items/%s", $m[2]);
$result = wp_remote_get($url);
if ( ! is_wp_error( $result ) && $result['response']['code'] === 200 ) {
$data = json_decode($result['body']);
return $data->rendered_body;
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment