You probably already know that we can add widgets to any widget area from Widgets setting page in WordPress Dashboard.

But did you know that you can display any widget on any template file? So for example you want to display a widget in the header but there’s no widget area in the header. What would you do?

the_widget function comes to the rescue!

You can use the code below to load any widget on any template file.

the_widget( $widget, $instance, $args );
  • $widget = widget’s PHP class name
  • $instance = widget’s instance settings
  • $args = widget’s sidebar args, for example before_widget, before_title and so on

To know all of the above parameter, you will need to open the widget file.

So, let say you want to display the Search widget in the header. Open up header.php file then put this code in the place where you want the widget to appear:

the_widget( 'WP_Widget_Search' );

Another example, use this code to display Category widget and display it as dropdown:

the_widget( 'WP_Widget_Categories', 'dropdown=1' );

Editorial Staff

aThemeArt Editorial Staff prepares and cooks all the content that are published on athemeart.com. They are responsible for all type of web content including blog, social posts, videos, documentation etc.

test

Leave a Reply

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

2 × 3 =

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

NEW FREE THEME! BC IS HERE GET FREE THEME