WordPress ワンポイントメッセージ表示ショートコード

概要説明

おすすめやワンポイントアドバイス、補足説明を強調して表示したい際に使うカスタマイズ。ショートコード内にスタイル定義を含めているのでサイトに合わせて調整いただけます。

functions.php
/*----------------------------------------------------
 おすすめなど強調した時に活用
----------------------------------------------------*/
add_shortcode( 'one_point',  'SCFstyleOnePoint' );

function SCFstyleOnePoint( $atts ) {

    extract( shortcode_atts( array(
       'title' => '',
       'msg'   => '',
       'color' => '#85db8f'
    ), $atts) );

    global $f_point_cnt;
    if (!isset($f_point_cnt)) {
        $f_point_cnt = 1;
    } else {
        $f_point_cnt++;
    }

    $msg = str_replace('&lt;',      '<',$msg);
    $msg = str_replace('&#8217;',   '', $msg);
    $msg = str_replace('&#8242;',   '', $msg);

    $title = str_replace('&#8217;', '', $title);
    $title = str_replace('&#8242;', '', $title);

    $color = str_replace('&#8217;', '', $color);
    $color = str_replace('&#8242;', '', $color);

    $html =<<<EOS
        <style type="text/css">
            .fpoint{$f_point_cnt} {
                position: relative;
                border: 1px solid #eee;
                border-radius: 4px;
                margin:50px auto!important;
            }
            .fpoint{$f_point_cnt} {
                border-color: {$color}!important;
                padding: 20px 25px;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
            }
            .fpoint{$f_point_cnt}:before {
                position: absolute;
                font-weight: bold;
                background: #fff;
                color: #555;
                line-height: 0;
                letter-spacing: 0;

                font-size: 20px;
                top: -21px;
                padding: 20px 8px 20px 0px;
            }
            .fpoint{$f_point_cnt}:before {
                content: "{$title}"!important;
                color: {$color}!important;
            }
        </style>
        <p class="fpoint{$f_point_cnt}">{$msg}</p>
    EOS;

    return $html;
}

動作サンプル ( 一部タグも使用可能 )

ショートコード
[one_point title="サンプル1" msg="カラー指定なし"]

カラー指定なし

ショートコード
[one_point title="サンプル2" msg="カラー指定あり" color="#ff0000"]

カラー指定あり

ショートコード
[one_point title="サンプル3" msg="カラー指定あり<br>改行あり" color="#b0cfd2"]

カラー指定あり
改行あり

注意事項 – ダブルクオーテーション「”」に注意

テキスト内にダブルクオーテーションは使えません

関連機能

  1. WordPressランダムに1件記事を表示させるショートコード ( カスタム投稿、任意の件数に対応 )

  2. WordPressプラグインなしでカスタム投稿をタイトル、本文、アイキャッチ、カテゴリーを有効にして設定

  3. RSSフィードにnoindexヘッダーを追加 ( Google Search Console 対策 )

サイドバー

よく使うカスタマイズ

最近の記事

アニメの名言集

「それでも」と言い続けろ
自分を見失うな

機動戦士ガンダムUC
by マリーダ・クルス

Profile

PAGE TOP
Amazon プライム対象