teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

追記・修正

2020/04/15 04:58

投稿

CHERRY
CHERRY

スコア25234

answer CHANGED
@@ -9,4 +9,29 @@
9
9
 
10
10
  投稿編集時に本文に埋め込まれていますので、RSS だけ属性値を含めないという設定はありません。
11
11
 
12
- 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) 等で、置き換えたい部分を置き換える必要があります。
12
+ 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) 等で、置き換えたい部分を置き換える必要があります。
13
+
14
+ ----
15
+
16
+ 追記
17
+
18
+ どのような 文字列が出力されているか不明なので、質問に記載されている属性から適当な <img> タグにしてみましたが、サンプルイメージとしては、
19
+
20
+ ```
21
+ function rss_replace_252724($content) {
22
+ $patterns = array();
23
+ $replacements = array();
24
+ $patterns[0] = '/<img src="(.*)" alt="(.*)" caption="(.*)" data-◯◯◯/>/'; // 検索するパターン
25
+ $replacements[0] = '<img src="$1" alt="$2" caption="$3"/>'; // 置き換える文字列
26
+ $content = preg_replace($patterns, $replacements, $content);
27
+ return $content;
28
+ }
29
+ add_filter( 'the_excerpt_rss', 'rss_img_replace_252724');
30
+ add_filter( 'the_content_feed', 'rss_img_replace_252724');
31
+ ```
32
+
33
+ のような感じでしょうか。
34
+
35
+ $patterns の `検索するパターン`の部分に検索対象にしたい文字列を正規表現形式で記載してして、$replacements の `置き換える文字列` の部分に置き換えた後の文字列を指定して、置き換えます。
36
+
37
+ 詳しくは、[preg_replace()](https://www.php.net/manual/ja/function.preg-replace.php) を参照。

1

追記修正

2020/04/15 04:58

投稿

CHERRY
CHERRY

スコア25234

answer CHANGED
@@ -7,6 +7,6 @@
7
7
 
8
8
  投稿の本文に含まれる <img> タグは、投稿編集画面で、本文に画像を貼り付けた際に属性値も設定されて、データベースに保存されます。
9
9
 
10
- 投稿編集時に本文に埋め込まれていますので、RSS だけ含めないという設定はありません。
10
+ 投稿編集時に本文に埋め込まれていますので、RSS だけ属性値を含めないという設定はありません。
11
11
 
12
12
  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) 等で、置き換えたい部分を置き換える必要があります。