WordPress the_widget function

WordPress the_widget

WordPress the_widget functions are PHP objects with the template and arguments in them and are used for displaying the blocks in the sidebar of your website. It helps to display these blocks outside the sidebar if required.

the_widget( string $widget, array $instance = array(), array $args = array() )

Official Definition: Output an arbitrary widget as a template tag.

Parameters:

$widget: (string) (Required) The widget’s PHP class name (see class-wp-widget.php).

$instance: (array) (Optional) The widget’s instance settings.
Default value: array()

$args: (array)(Optional) Array of arguments to configure the display of the widget.

    • ‘before_widget’
      (string) HTML content that will be prepended to the widget’s HTML output. Default <div class="widget %s">, where %s is the widget’s class name.
    • ‘after_widget’
      (string) HTML content that will be appended to the widget’s HTML output. Default </div>.
    • ‘before_title’
      (string) HTML content that will be prepending to the widget’s title when display. Default <h2 class="widgettitle">.
    • ‘after_title’
      (string) HTML content that meant to be appending to the widget’s title when display. Default </h2>.

Default value: array()


The parameter $widget refer’s a class.  There are some of the default classes for the widgets in WordPress are:

  1. WP_Widget_ArchivesArchives — display a monthly archive list.
  2. WP_Widget_CalendarCalendar — display a Calendar view of the posts.
  3. WP_Widget_CategoriesCategories — display a Calendar view of the categories.
  4. WP_Widget_LinksLinks — display the list of links (blogroll) in categories.
  5. WP_Widget_MetaMeta — display site meta. (Log in/out, admin, feed, and WordPress links )
  6. WP_Widget_PagesPages — display the list of Pages.
  7. WP_Widget_Recent_CommentsRecent Comments — display the list of Recent Comments.
  8. WP_Widget_Recent_PostsRecent Posts — display the list of Recent Posts.
  9. WP_Widget_RSSRSS — display a list of entries from any RSS or Atom feed.
  10. WP_Widget_SearchSearch (a search from) — to add a wp search form for the default search feature.
  11. WP_Widget_Tag_CloudTag Cloud — a list of the tags in cloud format.
  12. WP_Widget_TextText —  to add some extra custom text information.
  13. WP_Nav_Menu_WidgetNav Menu — to display the navigation menu.
  14. WP_Widget_Custom_HTML — HTML — to add custom HTML content.

Example:

<?php the_widget( 'WP_Widget_Archives', $instance, $args ); ?>

You can check the detail about the wordpress the_widget function here.
To get to know more about other JQuery topics, you can check these articles too.

Please follow and like us:

Related Posts

Leave a Reply

Share