テーマをCocoonに変更しました!

URLを指定するだけでスクリーンショットを表示するWordPressショートコード

wordpress

20131225170235

タイトル通りURLを書くだけでサイトのスクリーンショットを表示出来ちゃう超便利なソースです。

プラグインを使わずにfunctions.phpに書き足すだけでOKですよー

私このブログでも使わさせて頂いています

因みに私のサイトだと下のように表示されます。

[wpshot url=”https://webcss.withrun.org/” link=”0″]

詳しくはこちらのサイトを見てくださいね

[wpshot url=”http://m.designbits.jp/12071410/”] [WordPress] URLを指定してサイトのスクリーンショットを表示するショートコード(WordPress.comのAPIを使用)

functions.phpに以下のコードをコピーします

    // WordPress APIでスクリーンショットを表示するショートコード
    function get_wp_screenshot($attr) {
    extract(shortcode_atts(array(
    // デフォルト設定
    'url' => '',
    'alt' => '',
    'class' => '', // imgタグに付加するclass名
    'width' => 0, // 画像の幅(0の場合はwidthタグを出力しない)
    'link' => 1 // 0:リンクしない 1:リンクする
    ), $attr));
    if ($url == '') {
    return;
    }
    $image = 'http://s.wordpress.com/mshots/v1/' . urlencode(clean_url($url));
    if ($width > 0) {
    $height = floor($width/4*3);
    $image .= '?w=' . $width;
    $image_wh = ' width="' . $width . '" height="' . $height . '"';
    }
    if ($class != '') {
    $image_wh .= ' class="' . $class . '"';
    }
    $image = '<img src="' . $image . '" alt="' . $alt . '"' . $image_wh . '>';
    if ($link == 1) {
    $image = '<a href="' . $url . '" target="_blank">' . $image . '</a>';
    }
    return $image;
    }
    add_shortcode('wpshot','get_wp_screenshot');

 使い方は

投稿記事の中で、以下のようにショートコードを書けばスクリーンショットが表示されますよー

[wpshot url="スクリーンショットを撮るURL" width="幅" alt="説明" class="クラス名"]

画像にリンクをはりたくない場合以下

[wpshot url="http://wordpress.com/" link="0"]

凄い便利なソースご馳走様でした

ブログ管理者などによく売れてる本です

コメント

タイトルとURLをコピーしました