0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[WordPress]ショートコード

Posted at

ショートコード

WordPress では「ショートコード (shortcode)」という仕組みがあり、
[ショートコード名] のように書くと、対応する関数が実行される。

add_shortcode()の書式

add_shortcode('ショートコード名', '関数名');

仕組みの流れ

  • 関数を定義し、ショートコードを登録
// functions.php などに記述

// 関数定義
function my_hello_func() {
    return "こんにちは!これはショートコードです。";
}

// ショートコードを登録
add_shortcode('hello', 'my_hello_func');
  • 投稿や固定ページに記述
[hello]
  • 出力
こんにちは!これはショートコードです。

まとめ

WordPress では

  • [ショートコード名] で囲んで関数を呼び出す仕組みが「ショートコード」
    • 自分で add_shortcode() で登録するか、プラグインが提供しているショートコードを利用
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?