おすすめの画像を背景として使用する投稿を作成しようとしています。画像が選択されていない場合は、背景色にする必要があります。
こことGoogleの両方を検索しましたが、このコードしか見つかりませんでした。
<?php
if (has_post_thumbnail( $post->ID ) ):
$image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
else:
$image_attributes = array( '#fa5252; opacity:1!important' );
endif;
?>
<div style="background: url(<?php echo $image_attributes[0]; ?>)"></div>
言うまでもなく、それはまったく機能しません。