-
-
Save tenman/b3020a9a6ac57c901e3886038233a4c0 to your computer and use it in GitHub Desktop.
Corporate Plusテーマのヘッダー画像をアイキャッチ画像に変更
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Corporate Plusテーマのヘッダー画像を、個別投稿などでは、アイキャッチを表示するようにカスタマイズ | |
* カスタマイズの方針は、 | |
* 404等 $postがセットされていないページ以外で、 | |
* 個別投稿またはページで | |
* アイキャッチ画像が存在するなら | |
* ヘッダー画像のURLをアイキャッチ画像のURLに置き換える | |
*/ | |
if ( ! function_exists( 'corporate_plus_dynamic_css' ) ) : | |
//このif文が書いてある関数は、コピーしてチャイルドテーマに貼り付けても大丈夫 | |
//コピーしたら 必要な部分をカスタマイズしていきます。 | |
function corporate_plus_dynamic_css() { | |
global $corporate_plus_customizer_all_values,$post; | |
/*Color options */ | |
$corporate_plus_primary_color = $corporate_plus_customizer_all_values['corporate-plus-primary-color']; | |
$custom_css = ''; | |
//使用する変数のデフォルト値をセット | |
$use_post_thumbnail = false; //アイキャッチが使用される場合のフラッグを作る | |
$bg_image_url = ''; | |
$bg_image_width = ''; | |
$bg_image_height = ''; | |
/*background*/ | |
if( isset( $post ) && // 404等 $postがセットされていないページ以外で、 | |
is_singular() && // 個別投稿またはページで | |
has_post_thumbnail() // アイキャッチ画像が存在するなら | |
) { | |
$bg_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); | |
//ヘッダー画像のURLをアイキャッチ画像のURLに置き換える | |
//配列なので、URLだけ取り出す。 | |
//中身を確認するには、 var_dump( $bg_image_url ); | |
$bg_image_url = esc_url( $bg_image_url[0] ); | |
//必要なら、サイズを使って いろいろできます。(ここは省略) | |
$bg_image_width = $bg_image_url[ 1 ]; | |
$bg_image_height = $bg_image_url[ 2 ]; | |
$use_post_thumbnail = true; | |
}elseif( get_header_image() ){ | |
$bg_image_url = get_header_image(); | |
}else{ | |
$bg_image_url = get_template_directory_uri()."/assets/img/startup-slider.jpg"; | |
} | |
$custom_css .= " | |
.inner-main-title { | |
background-image:url('{$bg_image_url}'); | |
background-repeat:no-repeat; | |
background-size:cover; | |
background-attachment:fixed; | |
}"; | |
/*color*/ | |
$custom_css .= " | |
a:hover, | |
a:active, | |
a:focus, | |
.btn-primary:hover, | |
.widget li a:hover, | |
.posted-on a:hover, | |
.cat-links a:hover, | |
.comments-link a:hover, | |
.edit-link a:hover, | |
.tags-links a:hover, | |
.byline a:hover, | |
.nav-links a:hover, | |
.bx-controls-direction a:hover i, | |
.scroll-wrap.arrow:hover span { | |
color: {$corporate_plus_primary_color}; | |
}"; | |
/*background color*/ | |
$custom_css .= " | |
.navbar .navbar-toggle:hover, | |
.main-navigation .current_page_item > a:before, | |
.main-navigation .current-menu-item > a:before, | |
.main-navigation .active > a:before, | |
.main-navigation .current_page_ancestor > a:before, | |
.comment-form .form-submit input, | |
.read-more, | |
.btn-primary, | |
.circle, | |
.line > span, | |
.wpcf7-form input.wpcf7-submit, | |
.wpcf7-form input.wpcf7-submit:hover, | |
.breadcrumb{ | |
background-color: {$corporate_plus_primary_color}; | |
}"; | |
/*borders*/ | |
$custom_css .= " | |
.blog article.sticky, | |
.btn-primary:before{ | |
border: 2px solid {$corporate_plus_primary_color}; | |
}"; | |
$custom_css .= " | |
.comment-form .form-submit input, | |
.read-more{ | |
border: 1px solid {$corporate_plus_primary_color}; | |
}"; | |
$custom_css .= " | |
.wpcf7-form input.wpcf7-submit::before { | |
border: 4px solid {$corporate_plus_primary_color}; | |
}"; | |
$custom_css .= " | |
.breadcrumb::after { | |
border-left: 5px solid {$corporate_plus_primary_color}; | |
}"; | |
/*custom css*/ | |
/*custom css*/ | |
$corporate_plus_custom_css = wp_strip_all_tags ( $corporate_plus_customizer_all_values['corporate-plus-custom-css'] ); | |
if ( ! empty( $corporate_plus_custom_css ) ) { | |
$custom_css .= $corporate_plus_custom_css; | |
} | |
wp_add_inline_style( 'corporate-plus-style', $custom_css ); | |
} | |
endif; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment