タイトルに記述してある通りです。
WordPressのphpですべての画像に onerror
属性を付与したいです。
最初はJSで対応していたのですが、phpで実装しなければならなくなりうまくできず困っています。
コードは以下です。
php
1 2add_filter( 'the_content', 'insert_attribute'); 3 4function insert_attribute( $html ) { 5 $url = "imageUrl"; 6 preg_match_all("/<img(.+?)>/", $html, $images); 7 for($i = 0; $i < count($images); $i++) { 8 $images[$i]->setAttribute("onerror", $url); 9 } 10 return $html; 11}
どうかよろしくお願いします。