How To Add Default Header Image In WordPress?

WordPress, let’s you create theme support for header image, from which you can better brand out your site. Also, what if you are creating the WordPress theme to be used in your clients site and you want to provide default header image for that theme. Well, WordPress has you got covered up in that. It can help you to add default header image in your built in theme by just passing extra parameter in add_theme_support( 'custom-header' );, which we will learn here.

What is header image in WordPress?

Well the answer to that is, it is the main image for your site, which can better brand your site. Also, you may be better to utilize it linking back to the home page of your site. Or maybe, if you are trying to add link to other site via that banner, then, you can utilize it too for that purpose.

Header image in WordPress, has many of the feature to be included within it. Some of them are adding the fixed width and height as well as change those as required. Similarly, you can add the support for header media via same method.

Now, since having surface look onto the header image in WordPress, now let’s move ahead and learn about how to add default header image in WordPress, shall we?

How To Add Default Header Image In WordPress?

First of all, to add default header image in WordPress, you need to know about how to add theme support for custom header in WordPress. For that, you can follow our previous article, about how to do the same. However, if you just want to know it in brief then, you can add the below PHP code in the functions.php file of the there, which is from that very article:

There, in the above PHP code, you can see that we also added the parameter of 'default-image' => '', from which, we set the default header image for the current or future theme ult for WordPress. So, how to modify that PHP code for default image? Well, in this context, you need to modify that array value pointing out to the image path, where the image is located within the theme. For eg: you can do as below:

Here, since we are using the child theme for same, we have use the function: get_stylesheet_directory_uri(), however if you are using the main theme then, you can utilize the function: get_template_directory_uri() for same. So, that parameter since now points to the image uri, you will now see that when you add the theme on fresh WordPress install, you can see the default header image being applied to and is suggested too under the header image section.

Now, if you have done the same as we did for your built in WordPress theme then, you can see the similar results for your site too as below.

Output of How To Add Default Header Image In WordPress?

Since you have already done/modified the theme code for your site as needed for same, you can see the similar result output for your site too as we have, in the below screenshot:

You may also want to read:

  1. Display Date As Set In WordPress Date Format Setting
  2. Creating Contact Us Page Via Contact Form 7 Plugin
  3. Display Author Bio Without The Use Of Plugin
  4. Solve Maximum Execution Time Of 60 Seconds Exceeded
  5. Setting Up Static Front Page And Blog Page In WordPress

Conclusion

If you have followed up the tutorial properly and now can add default header image within your WordPress theme with ease then, we can say that you are now more familiar on this than before. However, if you are still confused on the same and want to know more about it then, do drop the comment below in the comment box and we will follow it up.

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.