LoginSignup
3
3

More than 5 years have passed since last update.

ルートラボのコースをWordPressの記事に埋め込む

Last updated at Posted at 2013-08-03

下記コードをfunction.phpに追加。あとはルートラボのコースのURLを記事にはりつけるだけ。

wp_embed_register_handler( 'latlonglab', '#http://latlonglab\.yahoo\.co\.jp/route/watch\?id=([0-9a-z]+)#i', 'wp_embed_handler_latlonglab' );

function wp_embed_handler_latlonglab( $matches, $attr, $url, $rawattr ) {

    $width  = get_option('embed_size_w');
    if(intval($width) === 0 ){
        $width = $GLOBALS['content_width'];
        $height = intval($width * 0.75);
    }else{
        $height = get_option('embed_size_h');
    }

    $embed = sprintf(
            '<script type="text/javascript" encoding="UTF-8" src="http://latlonglab.yahoo.co.jp/route/paste?id=%s&width=%d&height=%d&mapstyle=map&graph=true&maponly=false"></script>',
            esc_attr($matches[1]),
            $width,
            $height
            );

    return apply_filters( 'embed_latlonglab', $embed, $matches, $attr, $url, $rawattr );
}

完了

TODO

  • ショートコードでwidth, height オプション使えるようにする
  • 他の表示オプション使いたい人いるのかな?いたらショートコードで使えるようにする?
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3