ワードプレスのテーマtwentytwentyを基盤に、管理者画面のメディアライブラリで投稿した画像が表示されないエラーを対処する実装を行ったので、備忘録的にこの記事を残す。
環境情報
PHP:version 7.3.12
WordPress:version 5.5.3
WPテーマ:twentytwenty
対処法
修正を行うには、直接admin-ajax.phpファイルを書き換える必要があります。
変更前
wp-admin/admin-ajax.php
header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
変更後
wp-admin/admin-ajax.php
if( in_array( $_POST['action'], array( 'query-attachments', 'send-attachment-to-editor' ))){
header( 'Content-Type: application/json; charset=' . get_option('blog_charset' ));
}else{
header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
}
header( 'X-Robots-Tag: noindex' );