<?php
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*
* @package GridRead WordPress Theme
* @copyright Copyright (C) 2025 ThemesDNA
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
* @author ThemesDNA <themesdna@gmail.com>
*/

function gridread_widgets_init() {

register_sidebar(array(
    'id' => 'gridread-header-widgets',
    'name' => esc_html__( 'Header Right Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is located on the right side of the header of your web page. You can drag and drop a "Custom HTML" widget into this widget area and add your 728x90 banner ad code into that widget. You need to select "Header Layout" as "Logo + Header Banner" from theme options to display this widget area.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-header-widget widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="gridread-widget-title">',
    'after_title' => '</h2>'));

register_sidebar(array(
    'id' => 'gridread-sidebar-one',
    'name' => esc_html__( 'Sidebar 1 Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is located on the left-hand side of your web page.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-side-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-home-fullwidth-widgets',
    'name' => esc_html__( 'Top Full Width Widgets (Default HomePage)', 'gridread' ),
    'description' => esc_html__( 'This full-width widget area is located after the header of your website. Widgets of this widget area are displayed on the default homepage of your website (when you are showing your latest posts on homepage).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-fullwidth-widgets',
    'name' => esc_html__( 'Top Full Width Widgets (Everywhere)', 'gridread' ),
    'description' => esc_html__( 'This full-width widget area is located after the header of your website. Widgets of this widget area are displayed on every page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-home-left-top-widgets',
    'name' => esc_html__( 'Top Left Widgets (Default HomePage)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the left top of your website. Widgets of this widget area are displayed on the default homepage of your website (when you are showing your latest posts on homepage).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-left-top-widgets',
    'name' => esc_html__( 'Top Left Widgets (Everywhere)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the left top of your website. Widgets of this widget area are displayed on every page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-home-right-top-widgets',
    'name' => esc_html__( 'Top Right Widgets (Default HomePage)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the right top of your website. Widgets of this widget area are displayed on the default homepage of your website (when you are showing your latest posts on homepage).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-right-top-widgets',
    'name' => esc_html__( 'Top Right Widgets (Everywhere)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the right top of your website. Widgets of this widget area are displayed on every page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-home-top-widgets',
    'name' => esc_html__( 'Above Content Widgets (Default HomePage)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the top of the main content (above posts) of your website. Widgets of this widget area are displayed on the default homepage of your website (when you are showing your latest posts on homepage).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-top-widgets',
    'name' => esc_html__( 'Above Content Widgets (Everywhere)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the top of the main content (above posts) of your website. Widgets of this widget area are displayed on every page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-home-bottom-widgets',
    'name' => esc_html__( 'Below Content Widgets (Default HomePage)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the bottom of the main content (below posts) of your website. Widgets of this widget area are displayed on the default homepage of your website (when you are showing your latest posts on homepage).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-bottom-widgets',
    'name' => esc_html__( 'Below Content Widgets (Everywhere)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the bottom of the main content (below posts) of your website. Widgets of this widget area are displayed on every page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-home-left-bottom-widgets',
    'name' => esc_html__( 'Bottom Left Widgets (Default HomePage)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the left bottom of your website. Widgets of this widget area are displayed on the default homepage of your website (when you are showing your latest posts on homepage).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-left-bottom-widgets',
    'name' => esc_html__( 'Bottom Left Widgets (Everywhere)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the left bottom of your website. Widgets of this widget area are displayed on every page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-home-right-bottom-widgets',
    'name' => esc_html__( 'Bottom Right Widgets (Default HomePage)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the right bottom of your website. Widgets of this widget area are displayed on the default homepage of your website (when you are showing your latest posts on homepage).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-right-bottom-widgets',
    'name' => esc_html__( 'Bottom Right Widgets (Everywhere)', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the right bottom of your website. Widgets of this widget area are displayed on every page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-home-fullwidth-bottom-widgets',
    'name' => esc_html__( 'Bottom Full Width Widgets (Default HomePage)', 'gridread' ),
    'description' => esc_html__( 'This full-width widget area is located before the footer of your website. Widgets of this widget area are displayed on the default homepage of your website (when you are showing your latest posts on homepage).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-fullwidth-bottom-widgets',
    'name' => esc_html__( 'Bottom Full Width Widgets (Everywhere)', 'gridread' ),
    'description' => esc_html__( 'This full-width widget area is located before the footer of your website. Widgets of this widget area are displayed on every page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-single-post-bottom-widgets',
    'name' => esc_html__( 'Single Post Bottom Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is located at the bottom of single post of any post type (except attachments and pages).', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

register_sidebar(array(
    'id' => 'gridread-top-footer',
    'name' => esc_html__( 'Footer Top Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is located on the top of the footer of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-footer-widget widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2>'));

register_sidebar(array(
    'id' => 'gridread-footer-1',
    'name' => esc_html__( 'Footer 1 Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is the column 1 of the footer of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-footer-widget widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2>'));

register_sidebar(array(
    'id' => 'gridread-footer-2',
    'name' => esc_html__( 'Footer 2 Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is the column 2 of the footer of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-footer-widget widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2>'));

register_sidebar(array(
    'id' => 'gridread-footer-3',
    'name' => esc_html__( 'Footer 3 Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is the column 3 of the footer of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-footer-widget widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2>'));

register_sidebar(array(
    'id' => 'gridread-footer-4',
    'name' => esc_html__( 'Footer 4 Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is the column 4 of the footer of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-footer-widget widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2>'));

register_sidebar(array(
    'id' => 'gridread-bottom-footer',
    'name' => esc_html__( 'Footer Bottom Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is located on the bottom of the footer of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-footer-widget widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2>'));

register_sidebar(array(
    'id' => 'gridread-404-widgets',
    'name' => esc_html__( '404 Page Widgets', 'gridread' ),
    'description' => esc_html__( 'This widget area is located on the 404(not found) page of your website.', 'gridread' ),
    'before_widget' => '<div id="%1$s" class="gridread-main-widget widget gridread-widget-box %2$s"><div class="gridread-widget-box-inside">',
    'after_widget' => '</div></div>',
    'before_title' => '<div class="gridread-widget-header"><div class="gridread-widget-header-inside"><h2 class="gridread-widget-title"><span class="gridread-widget-title-inside">',
    'after_title' => '</span></h2></div></div>'));

}
add_action( 'widgets_init', 'gridread_widgets_init' );


function gridread_sidebar_one_widgets() {
    dynamic_sidebar( 'gridread-sidebar-one' );
}

function gridread_top_wide_widgets() { ?>

<?php if ( is_active_sidebar( 'gridread-home-fullwidth-widgets' ) || is_active_sidebar( 'gridread-fullwidth-widgets' ) ) : ?>
<div class="gridread-boxview-wrapper">
<div class="gridread-top-wrapper-outer gridread-clearfix">
<div class="gridread-content-widgets-area gridread-top-wrapper gridread-clearfix">
<?php if ( is_front_page() && is_home() && !is_paged() ) { ?>
<?php dynamic_sidebar( 'gridread-home-fullwidth-widgets' ); ?>
<?php } ?>

<?php dynamic_sidebar( 'gridread-fullwidth-widgets' ); ?>
</div>
</div>
</div>
<?php endif; ?>

<?php }


function gridread_bottom_wide_widgets() { ?>

<?php if ( is_active_sidebar( 'gridread-home-fullwidth-bottom-widgets' ) || is_active_sidebar( 'gridread-fullwidth-bottom-widgets' ) ) : ?>
<div class="gridread-boxview-wrapper">
<div class="gridread-bottom-wrapper-outer gridread-clearfix">
<div class="gridread-content-widgets-area gridread-bottom-wrapper gridread-clearfix">
<?php if ( is_front_page() && is_home() && !is_paged() ) { ?>
<?php dynamic_sidebar( 'gridread-home-fullwidth-bottom-widgets' ); ?>
<?php } ?>

<?php dynamic_sidebar( 'gridread-fullwidth-bottom-widgets' ); ?>
</div>
</div>
</div>
<?php endif; ?>

<?php }


function gridread_top_widgets() { ?>

<?php if ( is_active_sidebar( 'gridread-home-top-widgets' ) || is_active_sidebar( 'gridread-top-widgets' ) ) : ?>
<div class="gridread-content-widgets-area gridread-content-widgets-area-top gridread-clearfix">
<?php if ( is_front_page() && is_home() && !is_paged() ) { ?>
<?php dynamic_sidebar( 'gridread-home-top-widgets' ); ?>
<?php } ?>

<?php dynamic_sidebar( 'gridread-top-widgets' ); ?>
</div>
<?php endif; ?>

<?php }


function gridread_top_left_right_widgets() { ?>

<div class="gridread-left-right-wrapper gridread-clearfix">

<?php if ( is_active_sidebar( 'gridread-home-left-top-widgets' ) || is_active_sidebar( 'gridread-left-top-widgets' ) ) : ?>
<div class="gridread-left-top-wrapper">
<div class="gridread-content-widgets-area gridread-content-widgets-area-top gridread-clearfix">
<?php if ( is_front_page() && is_home() && !is_paged() ) { ?>
<?php dynamic_sidebar( 'gridread-home-left-top-widgets' ); ?>
<?php } ?>

<?php dynamic_sidebar( 'gridread-left-top-widgets' ); ?>
</div>
</div>
<?php endif; ?>

<?php if ( is_active_sidebar( 'gridread-home-right-top-widgets' ) || is_active_sidebar( 'gridread-right-top-widgets' ) ) : ?>
<div class="gridread-right-top-wrapper">
<div class="gridread-content-widgets-area gridread-content-widgets-area-top gridread-clearfix">
<?php if ( is_front_page() && is_home() && !is_paged() ) { ?>
<?php dynamic_sidebar( 'gridread-home-right-top-widgets' ); ?>
<?php } ?>

<?php dynamic_sidebar( 'gridread-right-top-widgets' ); ?>
</div>
</div>
<?php endif; ?>

</div>

<?php }


function gridread_bottom_left_right_widgets() { ?>

<div class="gridread-left-right-wrapper gridread-clearfix">

<?php if ( is_active_sidebar( 'gridread-home-left-bottom-widgets' ) || is_active_sidebar( 'gridread-left-bottom-widgets' ) ) : ?>
<div class="gridread-left-bottom-wrapper">
<div class="gridread-content-widgets-area gridread-content-widgets-area-bottom gridread-clearfix">
<?php if ( is_front_page() && is_home() && !is_paged() ) { ?>
<?php dynamic_sidebar( 'gridread-home-left-bottom-widgets' ); ?>
<?php } ?>

<?php dynamic_sidebar( 'gridread-left-bottom-widgets' ); ?>
</div>
</div>
<?php endif; ?>

<?php if ( is_active_sidebar( 'gridread-home-right-bottom-widgets' ) || is_active_sidebar( 'gridread-right-bottom-widgets' ) ) : ?>
<div class="gridread-right-bottom-wrapper">
<div class="gridread-content-widgets-area gridread-content-widgets-area-bottom gridread-clearfix">
<?php if ( is_front_page() && is_home() && !is_paged() ) { ?>
<?php dynamic_sidebar( 'gridread-home-right-bottom-widgets' ); ?>
<?php } ?>

<?php dynamic_sidebar( 'gridread-right-bottom-widgets' ); ?>
</div>
</div>
<?php endif; ?>

</div>

<?php }


function gridread_bottom_widgets() { ?>

<?php if ( is_active_sidebar( 'gridread-home-bottom-widgets' ) || is_active_sidebar( 'gridread-bottom-widgets' ) ) : ?>
<div class='gridread-content-widgets-area gridread-content-widgets-area-bottom gridread-clearfix'>
<?php if ( is_front_page() && is_home() && !is_paged() ) { ?>
<?php dynamic_sidebar( 'gridread-home-bottom-widgets' ); ?>
<?php } ?>

<?php dynamic_sidebar( 'gridread-bottom-widgets' ); ?>
</div>
<?php endif; ?>

<?php }


function gridread_404_widgets() { ?>

<?php if ( is_active_sidebar( 'gridread-404-widgets' ) ) : ?>
<div class="gridread-content-widgets-area gridread-content-widgets-area-top gridread-clearfix">
<?php dynamic_sidebar( 'gridread-404-widgets' ); ?>
</div>
<?php endif; ?>

<?php }


function gridread_post_bottom_widgets() {
    if ( is_singular() ) {
        global $post;
        if ( is_active_sidebar( 'gridread-single-post-bottom-widgets' ) ) : ?>
            <div class="gridread-content-widgets-area gridread-clearfix">
            <?php dynamic_sidebar( 'gridread-single-post-bottom-widgets' ); ?>
            </div>
        <?php endif;
    }
}