回答編集履歴
2
コードの修正
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
```php
|
8
8
|
|
9
|
-
function add_ads_before_
|
9
|
+
function add_ads_before_1st_h2($the_content) {
|
10
10
|
|
11
11
|
if (! is_single() || ! get_h2_included_in_body($the_content)) {
|
12
12
|
|
@@ -30,9 +30,9 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
-
$f = function ($matches) use (&$count, $
|
33
|
+
$f = function ($matches) use (&$count, $insert_position, $ad_template) {
|
34
34
|
|
35
|
-
return (++$count === $insert_position) ? $mat
|
35
|
+
return (++$count === $insert_position) ? $ad_template . $matches[0] : $matches[0];
|
36
36
|
|
37
37
|
};
|
38
38
|
|
1
追記
test
CHANGED
@@ -43,3 +43,11 @@
|
|
43
43
|
}
|
44
44
|
|
45
45
|
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
参考
|
50
|
+
|
51
|
+
PHP: preg_replace_callback - Manual
|
52
|
+
|
53
|
+
[http://php.net/manual/ja/function.preg-replace-callback.php](http://php.net/manual/ja/function.preg-replace-callback.php)
|