[WordPress]ショートコードをショートコードで囲む際の注意点

作成日:
  • セクションを作るためのショートコード:[section][/section]
  • テキストのフォントサイズを大きくするショートコード:[large][/large]
  • をそれぞれfunctions.phpに

    [php]function monoxa_section($atts, $content = null){
    return '

    '. $content .'

    ';
    }
    add_shortcode('section', 'monoxa_section');

    function monoxa_large($atts, $content = null){
    return ''. $content .'';
    }
    add_shortcode('large', 'monoxa_large');[/php]

    と作り、エディタで

    [html][section] こんにちは。私は[large]犬[/large]です。[/section][/html]

    と書いても、[section]しかコードに変換されません。
    shortcode1
    囲みショートコードで、その中にさらにショートコードが含まれることが想定される場合(今回は[section])、

    [php]function monoxa_section($atts, $content = null){
    $content = do_shortcode( shortcode_unautop( $content ) );
    return '

    '. $content .'

    ';
    }
    add_shortcode('section', 'monoxa_section');[/php]と、予め中のショートコードを実行するように記述しておく必要があるようです。
    shortcode2

    物草 灸太郎
    物草 灸太郎

    WordPressでホームページを制作しつつ、休日は畑を耕したりDIYを楽しんでいます。

    Loading...

    コメント

    ショートコードで囲みたい さん
    […] ショートコードをショートコードで囲む際の注意点 […]
    2014年12月31日 11:00 AM 返信

    ショートコードで囲みたい へ返信する

    • メールアドレスが公開されることはありません。
    • コメント欄にURLは入力できません。
    • このサイトはreCAPTCHAによって保護されており、Googleのプライバシーポリシー利用規約が適用されます。