【WordPress】Lazy BlocksのText Areaの出力に改行を入れる

  • URLをコピーしました!

【WordPress】Lazy Blocksの画像出力時にサムネイルサイズ設定をする

↑の応用です。

functions.php

function my_custom_lazyblock_handlebars_helper ( $handlebars )
{
    //  {{{nl2br hoge}}}
    $handlebars->registerHelper('nl2br', function ($data) {
        return nl2br($data);
    });
}
add_action( 'lzb_handlebars_object', 'my_custom_lazyblock_handlebars_helper' );

 

他のヘルパーも登録するときは、ひとつのfunctionにまとめて書けます。

function my_custom_lazyblock_handlebars_helper ( $handlebars )
{
//  {{{imgsize hoge 'custom-size'}}}
    $handlebars->registerHelper('imgsize', function ($img, $size) {
        $img=shortcode_atts(array('id'=>''),$img);//Warning: Illegal string offsetを防ぐ
        $imgdata = wp_get_attachment_image($img['id'], $size);
        return $imgdata;
    });

    //  {{{nl2br hoge}}}
    $handlebars->registerHelper('nl2br', function ($data) {
        return nl2br($data);
    });
}
add_action( 'lzb_handlebars_object', 'my_custom_lazyblock_handlebars_helper' );
よかったらシェアしてね!
  • URLをコピーしました!

コメント

コメントする

コメントは日本語で入力してください。(スパム対策)

CAPTCHA

目次