ショートコードの作り方【最短】

作り方

function sample() {
    return 'hello world!!!!!';
}
add_shortcode('helloWorld', 'sample');

直接入れてもよい

add_shortcode('helhelloWorldlo', function () {
    return 'hello world!!!!!';
});

呼び出し方

[helloWorld]

表示

hello world!!!!!

引数とかの使い方

function sample($atts, $content) {
  return 'hello '.$atts['state'].$content;
}
add_shortcode('hello', 'sample');

第一引数がHTMLでいうアトリビュート(連想配列)
第二引数がHTMLでいうテキスト

呼び出し方

[hello state="最強の"]田中さん[/hello]

表示

hello 最強の田中さん

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です