Register Default Headers – WordPress Snippet Generator

This tool is offered as a way to quickly and consistently generate and register Default Headers.

  • General
  • Header #1
  • #2
  • #3
  • #4
  • #5
  • #6
  • Code

General

Item
Input

Header #1

Item
Input

Header #2

Item
Input

Header #3

Item
Input

Header #4

Item
Input

Header #5

Item
Input

Header #6

Item
Input

Copy Code

Your customized theme support code snippet is below. Be sure to fully read the instructions that follow before adding this code to your WordPress theme.

Registers Default Headers

Add this code to your functions.php file. Scroll down to learn more.


// Default Headers
function {{themeSlug || 'your_theme_slug'}}_default_headers() {

	${{themeSlug || 'your_theme_slug'}}_headers = array(
		'{{header1key}}' => array(
			'description' => __( '{{header1desc}}', '{{textDomain || 'your-text-domain'}}' ),
			'url' => '{{header1img}}',
			'thumbnail_url' => '{{header1thumb}}',
		),
		'{{header2key}}' => array(
			'description' => __( '{{header2desc}}', '{{textDomain || 'your-text-domain'}}' ),
			'url' => '{{header1img}}',
			'thumbnail_url' => '{{header2thumb}}',
		),
		'{{header2key}}' => array(
			'description' => __( '{{header3desc}}', '{{textDomain || 'your-text-domain'}}' ),
			'url' => '{{header3img}}',
			'thumbnail_url' => '{{header3thumb}}',
		),
		'{{header2key}}' => array(
			'description' => __( '{{header4desc}}', '{{textDomain || 'your-text-domain'}}' ),
			'url' => '{{header4img}}',
			'thumbnail_url' => '{{header4thumb}}',
		),
		'{{header2key}}' => array(
			'description' => __( '{{header5desc}}', '{{textDomain || 'your-text-domain'}}' ),
			'url' => '{{header5img}}',
			'thumbnail_url' => '{{header5thumb}}',
		),
		'{{header2key}}' => array(
			'description' => __( '{{header6desc}}', '{{textDomain || 'your-text-domain'}}' ),
			'url' => '{{header6img}}',
			'thumbnail_url' => '{{header6thumb}}',
		)
	);
	register_default_headers( ${{themeSlug || 'your_theme_slug'}}_headers );

}
add_action( 'after_setup_theme', '{{themeSlug || 'your_theme_slug'}}_default_headers' );

    

WordPress themes generally follow an intuitive templating system that basically groups content into files based on their location and functionality on the website. For instance, all of the header’s content is neatly packed in a piece of code that is stored in the aptly named header.php file.

Adding a number of well-designed, default headers to your WordPress themes has a significant impact on their visual appeal. However, integrating default headers correctly into WordPress can be tricky – especially if this is your first time with theme development. With this in mind, we’ve put together this code snippet generator that allows both established developers and beginners register default headers in their WordPress themes.

Let’s take a closer look at what default headers are and the benefits of using them before we introduce the tool and explain how you can use it.

What Are Default Headers in WordPress and Do I Need Them?

WordPress themes come with a set of default headers right out of the box. Headers are basically images (of a certain dimension, depending upon the theme they’re used in) that are chosen as representative images in the theme’s top header section.

Twenty Seventeen theme

The default Twenty Seventeen header in all its glory.

Generally speaking, most WordPress themes have both header and footer areas that hold important information about your website. And since headers are located above the fold, most of your site’s visitors will notice them right off the bat before anything else. A well-designed default header can make a positive, lasting impression on the visitor.

Color palettes, typography, and image quality are all key factors that determine how effective and appealing your theme’s header is. For instance, a good header should allow text selecting.

How Do I Use This WordPress Default Header Snippet Generator Tool?

This code snippet generator tool is designed to help both seasoned WordPress theme developer and first-time theme builders get started with registering default headers. The tools allow you to register up to six default headers at a time. All you have to do is enter the required fields and the tool will output a custom code snippet for you.

Let’s take a look at the individual fields one by one:

  • General Tab

    • Theme Slug: Enter your theme’s slug into this text field in all lowercase letters, numbers and/or underscores. This value will be used to prefix functions and variables that would otherwise be incompatible with the WordPress core or any installed themes or plugins. Typically, this is the same string as the text domain, with underscores in place of hyphens.
    • Text Domain: The text domain works as a unique key that will be used to identify any translatable strings in your theme or plugin. It should be the same as your theme’s name in lowercase with spaces replaced by hyphens – in other words, it should match the theme’s directory name in the root folder.
  • Header #N Tab

    • Header #N Key: Enter the header’s key. It should be a unique identifier that points to the header’s array containing the URL, thumbnail URL, and menu description. This field accepts a string ID in all lowercase letters and hyphens (no spaces).
    • Image URL: Enter the URL of the image here. The header’s image should be registered before using it.
    • Thumbnail URL: Enter the URL for the thumbnail image here.
    • Menu Description: Enter a custom, descriptive summary for the header in this field such as custom-description, twentyseventeen.
  • Code Tab

    • Once you’ve enabled all of the options you’d like, navigate to the Code tab. You’ll find that the Register Default Headers text area is populated with a custom code snippet for adding default headers to your WordPress site.

 

How Do I Add the Code Snippets to My Website?

The quickest way to add the generated code snippet to your site is by pasting it directly into your current theme’s functions.php file. You can edit it directly by heading over to Appearance > Editor from the admin panel.

Alternatively, you can download the theme’s functions.php file to your desktop via an FTP client. Next, open it up in a text editor and paste the code at the bottom of the file. Hit the Save button and re-upload it to your theme’s directory. Once you’re done, the newly added custom default headers will be available for use.

Note: The function should not be called before the ‘init’ action.

Conclusion

We designed this tool to make it easier for WordPress developers to register and add default headers into their WordPress themes. Hopefully, this code snippet generator tool will save you some time and effort from having to write code by hand. We encourage you to give it a try in your next theme development project.

Do you have any questions about the Register Default Headers code generator tool? Let us know in the comments section below!


Written exclusively for

Nimbus Themes Publishing Logo

About the Author

Evan Scoboria is the co-founder, and developer at Shea Media LLC, the team behind Nimbus Themes, this magazine, and a bunch of very happy clients. He co-founded Shea Media with his wife Kendall in 2009. Evan enjoys hunting, fishing, code, cycling, and most of all WordPress!

Read all posts

2 Comments

  1. Jodie Miller Avatar

    Jodie Miller

    January 8, 2018 at 1:05 pm

    Hello, I am trying to add this to my wordpress site in the editor as describes above but i keep getting a message that the code is being inputted incorrectly and it wont let me continue. Can you help?

    Reply
    • sheamedia Avatar

      sheamedia

      January 9, 2018 at 8:30 am

      Hi Jodie,

      What does the code say exactly?

      Reply

Leave a Reply to Jodie Miller Cancel reply

Your email address will not be published. Required fields are marked *