###前提・実現したいこと
新着情報などに使用するサムネイル画像のサイズを変更したいです。
変更するためにインラインスタイルを除去したいのですが、どこまで修正してよいのかわかりませんでした。
###発生している問題
画像サイズをcssで指定しても、インラインスタイルの影響で反映されません。そして、ページコード内にstyle部分が見つからないのです。
###該当のソースコード
php
1echo '<div class="attachment-image">'."\n"; 2echo '<img src="'.esc_url( $att_image[0] ).'" width="'.intval( $att_image[1] ).'" height="'.intval( $att_image[2] ).'" class="attachment-full-size" alt="'.esc_attr( $att_excerpt ).'" />'."\n"; 3if ( ! empty( $att_excerpt ) ) { 4echo '<p class="attachment-text">'.esc_attr( $att_excerpt ).'</p>'."\n"; 5 } 6echo '</div>'."\n"; 7 } else { 8 the_content(); 9 } ?>
こちらはsingle.phpです。
###試したこと
cssでclass名を付けてサイズを指定したがインラインスタイルの方が強いために反映されない。ページコードをいじってみたが画像まで消えてしまう。
php
1echo '<img src="'.esc_url( $att_image[0] ).'" width="'.intval( $att_image[1] ).'" height="'.intval( $att_image[2] ).'" class="attachment-full-size" alt="'.esc_attr( $att_excerpt ).'" />'."\n";
single.phpのこのあたりにwidthやheightが記載されているので、intvalについても調べてみたのですがイマイチわかりませんでした。
※上記のsingle.phpのコードを変更しても反映されないのでfunction.phpにもサムネイルの情報がありましたのでそちらの可能性かと思いコードを追記しました。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
wordpress 4.7.1
theme:chocolate
php
以下にfunction.phpのコードを追加します。
php
1// 2.1.1 - post-thumbnails 2 add_theme_support( 'post-thumbnails' ); 3 4 // 2.1.1.0 - thumbnail image 5 $thumbnail_crop_x = ( ! empty( $options['thumbnail_crop_x'] ) ) ? esc_attr( $options['thumbnail_crop_x'] ) : 'center'; 6 $thumbnail_crop_y = ( ! empty( $options['thumbnail_crop_y'] ) ) ? esc_attr( $options['thumbnail_crop_y'] ) : 'center'; 7 set_post_thumbnail_size( 300, 300, array( $thumbnail_crop_x, $thumbnail_crop_y ) ); 8 9 // 2.1.1.1 - Registers a new image size (post_thumbnails, single-post-thumbnail) 10 $featured_size_w = ( ! empty( $options['featured_size_w'] ) ) ? absint( $options['featured_size_w'] ) : 700; 11 $featured_size_h = ( ! empty( $options['featured_size_h'] ) ) ? absint( $options['featured_size_h'] ) : 350; 12 $featured_crop = false; 13 14 if ( ! empty( $options['featured_crop'] ) ) { 15 if ( $options['featured_crop'] == 'crop' ) { 16 $featured_crop_x = ( ! empty( $options['featured_crop_x'] ) ) ? esc_attr( $options['featured_crop_x'] ) : 'center'; 17 $featured_crop_y = ( ! empty( $options['featured_crop_y'] ) ) ? esc_attr( $options['featured_crop_y'] ) : 'center'; 18 $featured_crop = array( $featured_crop_x, $featured_crop_y ); 19 } else { 20 $featured_crop = false; 21 } 22 } 23 24 // 2.1.1.2 - Changed the name to "single-post-thumbnail" from "post_thumbnail" 25 add_image_size( 'post_thumbnail', $featured_size_w, $featured_size_h, $featured_crop ); 26 add_image_size( 'single-post-thumbnail', $featured_size_w, $featured_size_h, $featured_crop ); 27 28 // 2.1.1.3 - Registers a new image size of home page (home-post-thumbnail) 29 if ( ! empty( $options['show_featured_home'] ) ) { 30 $featured_home_size_w = ( ! empty( $options['featured_home_size_w'] ) ) ? absint( $options['featured_home_size_w'] ) : 700; 31 $featured_home_size_h = ( ! empty( $options['featured_home_size_h'] ) ) ? absint( $options['featured_home_size_h'] ) : 350; 32 $featured_home_crop = true; 33 34 if ( ! empty( $options['featured_home_crop'] ) ) { 35 if ( $options['featured_home_crop'] == 'crop' ) { 36 $featured_home_crop_x = ( ! empty( $options['featured_home_crop_x'] ) ) ? esc_attr( $options['featured_home_crop_x'] ) : 'center'; 37 $featured_home_crop_y = ( ! empty( $options['featured_home_crop_y'] ) ) ? esc_attr( $options['featured_home_crop_y'] ) : 'center'; 38 $featured_home_crop = array( $featured_home_crop_x, $featured_home_crop_y ); 39 } else { 40 $featured_home_crop = false; 41 } 42 } 43 44/* ---------------------------------------------- 45 * 2.1.1 - post-thumbnails 46 * Image size square 47 * --------------------------------------------*/ 48 49if ( ! function_exists( 'chocolat_post_thumbnail' ) ) : 50function chocolat_post_thumbnail() { 51 $img_size = 300; 52 if ( has_post_thumbnail() ) { 53 the_post_thumbnail( 'thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) ); 54 } else { 55 global $post; 56 $str = $post->post_content; 57 $searchPattern = '/<img.*?src=(["\'])(.+?)\1.*?>/i'; 58 $noimage_url = get_template_directory_uri() .'/img/common/thumbnail.png'; 59 $img_class = ''; 60 61 if ( preg_match( $searchPattern, $str, $imgurl ) ) { 62 $noimage_url = $imgurl[2]; 63 $img_class = ' no-thumbnail-image'; 64 } else { 65 $options = chocolat_get_option(); 66 if ( ! empty( $options['no_image_url'] ) ) { 67 $noimage_url = $options['no_image_url']; 68 } 69 } 70 echo '<img src="'.esc_url( $noimage_url ).'" class="attachment-thumbnail wp-post-image'.esc_attr( $img_class ).'" alt="'.the_title_attribute( 'echo=0' ).'" width="'.absint( $img_size ).'" height="'.absint( $img_size ).'" />'; 71 } 72} 73endif; 74
回答3件
あなたの回答
tips
プレビュー