How to Customize the Twenty Seventeen Theme Navigation Menu
Content
Many users of the popular Twenty Seventeen WordPress theme encounter challenges when trying to customize their site's navigation. This can range from simple styling changes to more complex structural modifications for mobile and desktop views. Based on common community questions, this guide outlines the most frequent navigation issues and their solutions.
Common Navigation Challenges
Users often want to modify how the main menu behaves and appears. Frequent requests include:
- Changing the mobile menu breakpoint (the screen width at which the desktop menu switches to a hamburger button).
- Adding a search bar or other elements to the top navigation menu.
- Styling menu items specifically for mobile or desktop (e.g., link color).
- Creating a multi-line menu or forcing a line break.
- Making the sub-menu a full-width bar instead of a dropdown box.
Why These Issues Occur
The Twenty Seventeen theme uses a responsive design that automatically adjusts the menu layout based on screen size. This behavior is controlled by a combination of CSS media queries and JavaScript. Customizations that only address one part of this system (e.g., only CSS) may not work completely, leading to the menu toggle button not functioning or styles not applying correctly on all devices.
Most Common Solutions
1. Changing the Mobile Menu Breakpoint
The default breakpoint is 48em. To change it to 59em (or 916px), you must override both the CSS and the JavaScript logic. Inserting the following code in the Additional CSS section is a start, but it is often not sufficient on its own:
@media screen and (max-width: 59em) {
.js .menu-toggle,
.js .dropdown-toggle {
display: block;
}
.main-navigation ul {
display: none;
}
}
@media screen and (min-width: 59.001em) {
.main-navigation ul {
display: block;
}
}
As noted in the community threads, this CSS change may make the button visible, but the JavaScript file that controls the toggle functionality may still be using the original breakpoint. For a complete solution, creating a child theme and enqueuing a modified JavaScript file that updates the breakpoint value is often necessary.
2. Adding a Search Bar to the Top Menu
This requires modifying a theme file. The safest method is to use a child theme. In the child theme's header.php file, locate the <nav> element with the class .main-navigation. You can add the WordPress search form function inside this element, after the menu, to place it within the navigation bar.
<?php get_search_form(); ?>
You will then need to use CSS to style and position the search form appropriately within the menu bar.
3. Mobile-Only Styling
To change the color of top menu links only on mobile devices, use a CSS media query that targets smaller screen sizes. Avoid using PHP conditionals like wp_is_mobile() in the header, as this can cause caching issues. The following code added to Additional CSS is more reliable:
@media screen and (max-width: 48em) {
ul#top-menu a {
color: #fff;
}
}
4. Creating a Multi-Line Menu
To force a menu to wrap after a specific item, you can use CSS. First, identify the unique ID or class of the menu item you want to be the last on the first line. Using browser developer tools (F12) is the easiest way to find this. Then, add a line break using the ::after pseudo-element.
#menu-item-123::after {
content: "A";
white-space: pre;
}
Important Recommendation: Use a Child Theme
For any solution that involves modifying theme files (PHP, JS), it is highly recommended to use a child theme. This ensures your customizations are not overwritten when the Twenty Seventeen theme receives an update.
Customizing theme navigation often requires a mix of CSS and PHP adjustments. For more complex changes, such as registering a new navigation menu area or significantly altering the menu's structure, custom development work is typically needed beyond simple snippets.
Related Support Threads Support
-
Defining AMP Menu Positionhttps://wordpress.org/support/topic/defining-amp-menu-position/
-
Line break in top menuhttps://wordpress.org/support/topic/line-break-in-top-menu/
-
Full-width submenuhttps://wordpress.org/support/topic/full-width-submenu/
-
Add site title to menubar and fix dropdownhttps://wordpress.org/support/topic/add-site-title-to-menubar-and-fix-dropdown/
-
change top menu links color in mobile deviceshttps://wordpress.org/support/topic/change-top-menu-links-color-in-mobile-devices/
-
Change browser width where menu becomes a buttonhttps://wordpress.org/support/topic/change-browser-width-where-menu-becomes-a-button/
-
How to get Top Menu on all deviceshttps://wordpress.org/support/topic/how-to-get-top-menu-on-all-devices/
-
Remove the written menu from mobile and change iconhttps://wordpress.org/support/topic/remove-the-written-menu-from-mobile-and-change-icon/
-
Twenty Seventeen Search Bar on Top Menuhttps://wordpress.org/support/topic/twenty-seventeen-search-bar-on-top-menu-2/
-
Help Needed to create 2 Top menu barshttps://wordpress.org/support/topic/help-needed-to-create-2-top-menu-bars/
-
Hamburger menu on Twenty seventeen themehttps://wordpress.org/support/topic/hamburger-menu-on-twenty-seventeen-theme/
-
Move search field, fix menuhttps://wordpress.org/support/topic/move-search-field-fix-menu/
-
Move Top Navigation menu to left side barhttps://wordpress.org/support/topic/move-top-navigation-menu-to-left-side-bar/
-
How to register an additional navigation menu above titlehttps://wordpress.org/support/topic/how-to-register-an-additional-navigation-menu-above-title/
-
Mobile site top menu = social menu?https://wordpress.org/support/topic/mobile-site-top-menu-social-menu/
-
How to change the top menu linkhttps://wordpress.org/support/topic/how-to-change-the-top-menu-link/