How Do I Add a Sticky Header in WordPress?
Adding a sticky header in WordPress is a fairly simple process. First, you’ll need to create a header file in your theme folder. This file should include the following:
Next, you’ll need to add a reference to this header file in your theme’s stylesheet. To do this, you’ll need to open your theme’s main stylesheet file (usually located in the themes folder) and locate the section that includes the style rules for your website. In this example, the header file is located at the following location:
/wp-content/themes/my theme/style.css
Once you’ve located the header file, you’ll need to add a line of code that references it. To do this, you’ll need to locate the section of the stylesheet that defines the style for your website’s main header. In this example, the header style is defined as follows:.header { height: 100%; width: 100%; padding-top: 20px; }
To add a reference to the header file, you’ll need to add the following line of code to the .header section of the stylesheet:
@import “./header.
css”;.
Finally, you’ll need to add a rule that tells WordPress to use the header file as the main header for your website. To do this, you’ll need to locate the section of the stylesheet that defines the style for your website’s main body. In this example, the main body style is defined as follows:.main-body { height: 100%; width: 100%; }
To add a reference to the header file, you’ll need to add the following line of code to the .main-body section of the stylesheet:
Now that the header file and reference to it have been added, you’ll need to add a rule that tells WordPress to use the header file as the main header for your website. To do this, you’ll need to locate the section of the stylesheet that defines the style for your website’s main content area. In this example, the main content area style is defined as follows:.main-content { height: 100%; width: 100%; }
To add a reference to the header file, you’ll need to add the following line of code to the .main-content section of the stylesheet:
Now that the header file and reference to it have been added, you’ll need to add a rule that tells WordPress to use the header file as the main header for your website. To do this, you’ll need to locate the section of the stylesheet that defines the style for your website’s main footer. In this example, the main footer style is defined as follows:.main-footer { height: 100%; width: 100%; }
To add a reference to the header file, you’ll need to add the following line of code to the .main-footer section of the stylesheet:
Now that the header file and reference to it have been added, you’re finished adding a sticky header in WordPress!
Conclusion
.header { height.