Display Header Video In WordPress In Different Pages

WordPress, from the release of 4.7, let’s you support header video within the theme. However, if you support it, you will get the video in the home page only for your site. And other other pages, you will see only the header image. But what if you want to display header video in WordPress in different pages? Is it really doable? Well it is doable for your your site and you have come to the right place to learn about how to achieve it.

What is video header and how to add theme support for video header in WordPress?

Well, as described earlier, it is the feature in WordPress which is introduced in 4.7. It helps you to display header video in your site if theme supports it. However, by default, it is only available for the home page of your site.

Now, let’s jump ahead and learn about how to add theme support for video headers in your theme. Shall we?

For it, open up your functions.php file of the theme and then add the below PHP code in that file to support it:

Now, you will see the header video option available in the Customizer section of your site if you add it as mentioned.

You need to just add the YouTube url there or upload the video as needed for our site. However, adding the YouTube video is more preferred regarding the consideration of bandwidth for your site.

How to display video header in WordPress?

Now, after learning about how to add theme support for video header in WordPress, let’s move ahead and learn about how to display it, shall we?

Well for it, just open up the required theme file where you want it to be opened up. For our case, we will paste that in the header.php file of the theme. Now, after opening the required file, just add the below PHP code in the required area and it will work to display it:

You can see the output for it as in the screenshot below:

And you can learn here about adding theme support for video headers in WordPress in detail.

How to display header video in WordPress in different pages?

Now, since you have learnt about adding theme support for video header via your theme and also learnt about it is displaying in the home page of your site only. You may wonder if it is really possible to display it in any page of your site right? Well, we have got you covered up for this about how it will work for almost all of the pages added in your site.

For this to be achievable, you need to edit the functions.php file of the theme. And you need to know the hook onto which you can make it possible. Well, the hook name for it is: is_header_video_active. After knowing the hook which controls it, now let’s move ahead and apply it within your theme.

For it, you just need to add the below PHP code in that previously mentioned file:

In the above code, you can see that we have hooked the above mentioned function to our custom function, which is checking for single post page and single page. If you are now viewing either of those page in your site with addition of video header, you will see that the video header is now available for those pages too, while previously, it was only available for the home page of your site.

Output of adding theme support to display different header video in WordPress in different pages

Now, since you have learnt about how to implement the header video in other pages in your site too, now, you may be eager to learn on the output right? Well, below is the screenshot about how to display header video in WordPress in different pages of your site:

You may also want to read:

  1. How To Filter WordPress Content
  2. Check For Custom Post Types Condiotionally In WordPress
  3. Creating Scroll To Top Button Using jQuery
  4. Make YouTube And Vimeo Video Responsive In WordPress
  5. Controlling Number Of Posts To Be Displayed In Post Page

Conclusion

If you have followed up the tutorial properly and now can display header video in WordPress in different pages within your WordPress site 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.