回答編集履歴

2

追記・修正

2020/04/15 04:58

投稿

CHERRY
CHERRY

スコア25175

test CHANGED
@@ -21,3 +21,53 @@
21
21
 
22
22
 
23
23
  RSS で配信される場合のみ 本文に含まれる <img> タグを変更するのであれば、[the_excerpt_rss](https://developer.wordpress.org/reference/hooks/the_excerpt_rss/) フック や [the_content_feed](https://developer.wordpress.org/reference/hooks/the_content_feed/)の中で、本文に対して、[preg_replace()](https://www.php.net/manual/ja/function.preg-replace.php) 等で、置き換えたい部分を置き換える必要があります。
24
+
25
+
26
+
27
+ ----
28
+
29
+
30
+
31
+ 追記
32
+
33
+
34
+
35
+ どのような 文字列が出力されているか不明なので、質問に記載されている属性から適当な <img> タグにしてみましたが、サンプルイメージとしては、
36
+
37
+
38
+
39
+ ```
40
+
41
+ function rss_replace_252724($content) {
42
+
43
+ $patterns = array();
44
+
45
+ $replacements = array();
46
+
47
+ $patterns[0] = '/<img src="(.*)" alt="(.*)" caption="(.*)" data-◯◯◯/>/'; // 検索するパターン
48
+
49
+ $replacements[0] = '<img src="$1" alt="$2" caption="$3"/>'; // 置き換える文字列
50
+
51
+ $content = preg_replace($patterns, $replacements, $content);
52
+
53
+ return $content;
54
+
55
+ }
56
+
57
+ add_filter( 'the_excerpt_rss', 'rss_img_replace_252724');
58
+
59
+ add_filter( 'the_content_feed', 'rss_img_replace_252724');
60
+
61
+ ```
62
+
63
+
64
+
65
+ のような感じでしょうか。
66
+
67
+
68
+
69
+ $patterns の `検索するパターン`の部分に検索対象にしたい文字列を正規表現形式で記載してして、$replacements の `置き換える文字列` の部分に置き換えた後の文字列を指定して、置き換えます。
70
+
71
+
72
+
73
+ 詳しくは、[preg_replace()](https://www.php.net/manual/ja/function.preg-replace.php) を参照。

1

追記修正

2020/04/15 04:58

投稿

CHERRY
CHERRY

スコア25175

test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- 投稿編集時に本文に埋め込まれていますので、RSS だけ含めないという設定はありません。
19
+ 投稿編集時に本文に埋め込まれていますので、RSS だけ属性値を含めないという設定はありません。
20
20
 
21
21
 
22
22