回答編集履歴
1
情報の追加。
test
CHANGED
@@ -30,10 +30,48 @@
|
|
30
30
|
|
31
31
|
> }
|
32
32
|
|
33
|
-
```
|
33
|
+
> ```
|
34
34
|
|
35
35
|
|
36
36
|
|
37
37
|
【shortcode_atts – WordPress私的マニュアル】
|
38
38
|
|
39
39
|
[https://elearn.jp/wpman/function/shortcode_atts.html](https://elearn.jp/wpman/function/shortcode_atts.html)
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
**追記:**
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
「(link指定を忘れなければエラーは出ないとは思いますが、ミスをしない前提の書き方はお勧めしません) 」と書いているそのままの方法を採ったんですね・・・。
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```PHP
|
58
|
+
|
59
|
+
function my_shortcode( $atts, $content = '' ) {
|
60
|
+
|
61
|
+
$atts = shortcode_atts( [ 'link' => '' ], $atts, 'btn' );
|
62
|
+
|
63
|
+
return empty( $atts[ 'link' ] ) ? '' : sprintf(
|
64
|
+
|
65
|
+
'<div class="entry-btn"><a class="btn" href="%1$s">%2$s</a></div>'
|
66
|
+
|
67
|
+
, esc_url( $atts[ 'link' ] )
|
68
|
+
|
69
|
+
, apply_filters( 'the_content', $content )
|
70
|
+
|
71
|
+
);
|
72
|
+
|
73
|
+
} // 未テスト
|
74
|
+
|
75
|
+
add_shortcode( 'btn', 'my_shortcode' );
|
76
|
+
|
77
|
+
```
|