How to Reposition and Customize the Header in Twenty Twelve
Content
Customizing the header is one of the most common tasks for users of the Twenty Twelve theme. A frequent point of confusion is the theme's default structure, which places the navigation menu above the header image. Many users wish to reverse this order, center the image, or integrate other elements like text or videos. This guide covers the most effective methods to achieve these customizations.
Why This Happens
The Twenty Twelve theme is designed with a specific, responsive layout in mind. Its default behavior of placing the menu above the header image is intentional. To change this or any other core styling, modifications must be made. The safest and most recommended way to do this is by using a child theme, which protects your changes from being overwritten during theme updates.
Common Solutions
1. Moving the Header Image Above the Menu
This is the most requested change. The solution involves editing your child theme's header.php file to reposition the HTML code for the navigation menu.
- In your child theme, copy the
header.phpfile from the parent Twenty Twelve theme. - Locate the section of code that begins with
<nav id="site-navigation" class="main-navigation" role="navigation">. - Cut this entire navigation section and paste it below the section that contains the
<?php if ( get_header_image() ) : ?>conditional statement, which outputs the header image. - Save the file. The header image will now appear above the menu.
Note: Always test your site after making these changes, as altering the structure can sometimes affect the responsive design on mobile devices.
2. Centering the Header Image
If your header image is aligned to the left, you can center it with CSS. Add the following code to your child theme's style.css file or via a Custom CSS plugin:
.header-image {
display: block;
margin: 0 auto;
}
If this doesn't work, a more specific selector might be needed. Using a browser inspector tool like Firebug can help you identify the correct CSS class to target.
3. Removing the Shadow and Making the Header Transparent
To remove the box-shadow from the header image and make it transparent, use this CSS:
.header-image {
box-shadow: none !important;
background: transparent !important;
}
4. Adding a Default Header Image in a Child Theme
To set a default header image that won't be erased on update, avoid modifying the parent theme's functions.php. Instead, add the following code to your child theme's functions.php file to define a custom header:
function my_child_theme_setup() {
$args = array(
'default-image' => get_stylesheet_directory_uri() . '/images/your-default-image.jpg',
'width' => 1000,
'height' => 200,
'flex-width' => true,
'flex-height' => true,
);
add_theme_support( 'custom-header', $args );
}
add_action( 'after_setup_theme', 'my_child_theme_setup' );
Replace /images/your-default-image.jpg with the path to your image.
5. Creating a Full-Width Header
To make the header image span the full width of the page and remove the default white margins, you can use CSS to adjust the padding:
body .site {
padding-left: 0;
padding-right: 0;
}
#main, #colophon, #site-navigation {
padding-left: 30px;
padding-right: 30px;
}
Important Considerations
- Always Use a Child Theme: Directly editing the Twenty Twelve theme files is not recommended. Any changes will be lost when the theme is updated. A child theme ensures your customizations are preserved.
- Test Responsiveness: Twenty Twelve is a responsive theme. After making structural or CSS changes, always check how your site looks on different screen sizes (desktop, tablet, mobile).
- Use Browser Tools: Tools like Chrome Developer Tools or Firefox Firebug are invaluable for testing CSS changes in real-time before adding them to your theme files.
By following these methods, you can significantly alter the default header behavior of the Twenty Twelve theme to better suit your website's design. Remember to clear your cache after making changes to see the results.
Related Support Threads Support
-
[Theme: Twenty Twelve] Moving Header image above the menuhttps://wordpress.org/support/topic/theme-twenty-twelve-moving-header-image-above-the-menu/
-
Won't allow me to add an img in header.php filehttps://wordpress.org/support/topic/wont-allow-me-to-add-an-img-in-headerphp-file/
-
Fixed Header in TwentyTwelve Child themehttps://wordpress.org/support/topic/fixed-header-in-twentytwelve-child-theme/
-
how to center header imagehttps://wordpress.org/support/topic/how-to-center-header-image-4/
-
Want to put rss icon at the top of my site in my child theme (twenty twelve)https://wordpress.org/support/topic/want-to-put-rss-icon-at-the-top-of-my-site-in-my-child-theme-twenty-twelve/
-
background image of header and stretch header and footerhttps://wordpress.org/support/topic/background-image-of-header-and-stretch-header-and-footer/
-
Header logo.https://wordpress.org/support/topic/header-logo-42/
-
Remove margins on header imagehttps://wordpress.org/support/topic/remove-margins-on-header-image/
-
Center Header Image on Pagehttps://wordpress.org/support/topic/center-header-image-on-page/
-
Separating header image from site…creating space between site and headerhttps://wordpress.org/support/topic/separating-header-image-from-sitecreating-space-between-site-and-header/
-
Raise image where header would normally gohttps://wordpress.org/support/topic/raise-image-where-header-would-normally-go/
-
Header Below Menuhttps://wordpress.org/support/topic/header-below-menu/
-
Center the header?https://wordpress.org/support/topic/center-the-header-1/
-
move header image underneath site title (header text)?https://wordpress.org/support/topic/move-header-image-underneath-site-title-header-text/
-
Header – Align Justify Something to the right of the Titlehttps://wordpress.org/support/topic/header-align-justify-something-to-the-right-of-the-title/
-
Twenty twelve – how to put a mast head with links into my headerhttps://wordpress.org/support/topic/twenty-twelve-how-to-put-a-mast-head-with-links-into-my-header/
-
Header text and imagehttps://wordpress.org/support/topic/header-text-and-image/
-
Header/Menu Twenty Twelve themehttps://wordpress.org/support/topic/headermenu-twenty-twelve-theme/
-
Header image in Twelve Twelvehttps://wordpress.org/support/topic/header-image-in-twelve-twelve/
-
Header Image Helphttps://wordpress.org/support/topic/header-image-help-6/
-
Center headerhttps://wordpress.org/support/topic/center-header-5/
-
Twenty Twelve Header Image resize to full-widthhttps://wordpress.org/support/topic/twenty-twelve-header-image-resize-to-full-width/
-
How to re-position header image?https://wordpress.org/support/topic/how-to-re-position-header-image/
-
Change header for mobilehttps://wordpress.org/support/topic/change-header-for-mobile/
-
Youtube Video in Header (Position/Resizing)https://wordpress.org/support/topic/youtube-video-in-header-positionresizing/
-
Headerimage – Cutting the white space.https://wordpress.org/support/topic/header-63/
-
Setting default header image in child themehttps://wordpress.org/support/topic/setting-default-header-image-in-child-theme/
-
Inserting Slider into Header codehttps://wordpress.org/support/topic/inserting-slider-into-header-code/
-
Header Picture is on the wrong Placehttps://wordpress.org/support/topic/header-picture-is-on-the-wrong-place/
-
Adding logo image on top of header-imagehttps://wordpress.org/support/topic/adding-logo-image-on-top-of-header-image/