This post is also available in: English-US (英語)
wordpressにてtwentytwelveテーマを使用している際に、CSSでコンテンツの幅を変更しようとした時に横幅が変更できない場合があります。
原因は、twentytwelveテーマファイルのfunctions.phpにある twentytwelve_content_width() 関数で、自動でメインコンテンツの横幅が調整されるようになっています。
以下が該当する部分です。
/**
* Adjusts content_width value for full-width and single image attachment
* templates, and when there are no active widgets in the sidebar.
*
* 全幅テンプレート、アタッチメント画像テンプレート、"sidebar-1"のサイドバー
* がアクティブにされていない場合には、content_widthのwidthを自動調整しています。
*
* @since Twenty Twelve 1.0
*/
function twentytwelve_content_width() {
if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
global $content_width;
$content_width = 960;
}
}
add_action( 'template_redirect', 'twentytwelve_content_width' );
対処方法は上記のコードのうち $content_width の部分を、例えば1200pxにしたい場合には
$content_width = 1200;
のように書き換えて保存します。









