wordpressのtwentyseventeenのヘッダー画像サイズを統一する
wordpressのテーマ「Twenty Seventeen」を使ってみたのですが、ヘッダー画像(カスタムヘッダー画像)のサイズが、トップページと他のページではサイズが異なり、画像を上下左右最大限まで表示する必要があったので、その設定方法と苦労をメモしておきます。
1.まずは子テーマを作成します(これについては別途記載)
2.子テーマの「function.php」に以下を追加します。
// Eliminate twentyseventeen-front-page home css
// フロントページのヘッダー画像を他のページと統一する
add_filter( 'body_class', 'my_body_class',20 );
function my_body_class( $classes ) {
unset($classes[array_search("twentyseventeen-front-page",$classes)]);
unset($classes[array_search("home",$classes)]);
return $classes;
}
フロントページの画像を表示するプログラムを、他ページと同様の扱いにしてしまいます。
最初はトップページ、サブページのヘッダー画像をそれぞれCSSを探って変更したのですが、
IEと他のブラウザで見え方が違ったりと色々苦戦しました。
3.子テーマの「style.css」に以下を追加します。
.site-branding{
padding:30% 0 !important;
height: calc(100vh - 104px);
}
.panel-image {
background-position: center center;
background-repeat: no-repeat;
-webkit-background-size: cover;
background-size: 100%;
position: relative;
}
.has-header-image.twentyseventeen-front-page .custom-header,
.has-header-video.twentyseventeen-front-page .custom-hheadereader,
.has-header-image.home.blog .custom-header,
.has-header-video.home.blog .custom-header,
.has-header-image.twentyseventeen-front-page .custom-header img{
height: 100vh !important; /* 75vh */
max-width:100%;
}
.has-header-image .custom-header-media img,
.has-header-video .custom-header-media video,
.has-header-video .custom-header-media iframe {
position: absolute; /* fixed */
max-width:100%;
}
@media screen and (min-width: 48em) {
.has-header-image.twentyseventeen-front-page .custom-header,
.has-header-video.twentyseventeen-front-page .custom-header,
.has-header-image.home.blog .custom-header,
.has-header-video.home.blog .custom-header {
height: 100vh;
max-width:100%;
}
.twentyseventeen-front-page.has-header-image .custom-header-media,
.twentyseventeen-front-page.has-header-video .custom-header-media,
.home.blog.has-header-image .custom-header-media,
.home.blog.has-header-video .custom-header-media {
height: 100vh; /* 100vh */
max-width:auto;
width:100%;
}
}
.custom-header-media:before{
background:transparent !important;
}
/* powered by wordpress の文を削除*/
.site-footer .site-title:after {
content: "";
}
span.credit-link
{
display: none;
}
.site-info {
display: none;
}
ついでに、コピーライトも消しちゃいます。
メニューのエリアがファーストビューに収まらなかったり、メニューの下に変な空白ができちゃいますが
今は一旦ここまで。
また追加修正があれば書いていきます。
コメント
コメントを投稿