<?php
/**
 * Wellness Coach Lite Template Functions which enhance the theme by hooking into WordPress
 *
 * @package Wellness_Coach_Lite
 */

if( ! function_exists( 'wellness_coach_lite_doctype' ) ) :
/**
 * Doctype Declaration
*/
function wellness_coach_lite_doctype(){ ?>
    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <?php
}
endif;
add_action( 'wellness_coach_lite_doctype', 'wellness_coach_lite_doctype' );

if( ! function_exists( 'wellness_coach_lite_head' ) ) :
/**
 * Before wp_head 
*/
function wellness_coach_lite_head(){ ?>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <?php
}
endif;
add_action( 'wellness_coach_lite_before_wp_head', 'wellness_coach_lite_head' );

if( ! function_exists( 'wellness_coach_lite_page_start' ) ) :
/**
 * Page Start
*/
function wellness_coach_lite_page_start(){ ?>
    <div id="page" class="site">
        <a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content (Press Enter)', 'wellness-coach-lite' ); ?></a>
    <?php
}
endif;
add_action( 'wellness_coach_lite_before_header', 'wellness_coach_lite_page_start', 20 );

if( ! function_exists( 'wellness_coach_lite_header' ) ) :
/**
 * Header Start
*/
function wellness_coach_lite_header(){    
    $ed_cart   = get_theme_mod( 'ed_shopping_cart', true );
    $phone     = get_theme_mod( 'phone' );
    $email     = get_theme_mod( 'email' );
    $ed_banner = get_theme_mod( 'ed_banner_section', 'static_banner' ); ?>
        <header id="masthead" class="site-header style-one<?php if( $ed_banner ) echo ' no-banner'; ?>" itemscope itemtype="http://schema.org/WPHeader">      
            <?php if( ( wellness_coach_lite_social_links( false ) ) || $phone || $email || ( wellness_coach_lite_is_woocommerce_activated() && $ed_cart ) || ( current_user_can( 'manage_options' ) || has_nav_menu( 'secondary' ) ) ) : ?>
                <div class="header-top">
                    <div class="container">			
                        <?php if( wellness_coach_lite_social_links( false ) ){
                            echo '<div class="header-left"><div class="header-social">';
                            wellness_coach_lite_social_links();
                            echo '</div></div>';
                        } ?>  
                        <div class="header-center">
                            <?php wellness_coach_lite_header_contact(); ?>
                        </div>
                        
                        <div class="header-right">
                            <?php if( wellness_coach_lite_is_woocommerce_activated() && $ed_cart ) {
                                echo '<div class="header-cart">';
                                wellness_coach_lite_wc_cart_count();
                                echo '</div>';
                            } ?>
                            <?php wellness_coach_lite_secondary_navigation(); ?>
                        </div>
                    </div>
                </div>
            <?php endif; ?>
            <div class="header-main">
                <div class="container">
                    <?php wellness_coach_lite_site_branding(); ?>
                    <?php wellness_coach_lite_primary_navigation(); ?>
                    <?php wellness_coach_lite_contact_button(); ?>
                </div>
            </div>
            <?php wellness_coach_lite_mobile_navigation(); ?>
        </header>
    <?php 
    }
endif;
add_action( 'wellness_coach_lite_header', 'wellness_coach_lite_header', 20 );

if( ! function_exists( 'wellness_coach_lite_content_start' ) ) :
/**
 * Content Start
 *   
*/
function wellness_coach_lite_content_start(){       
    echo '<div id="content" class="site-content">';

    if( !( is_front_page() && ! is_home() ) && ! is_404() ) wellness_coach_lite_page_header();
    
    if( !( is_front_page() && ! is_home() ) ) echo '<div class="container">';

    if( is_home() ) wellness_coach_lite_page_header_top_picks();
}
endif;
add_action( 'wellness_coach_lite_content', 'wellness_coach_lite_content_start' );

if( ! function_exists( 'wellness_coach_lite_article_meta' ) ) :
/**
 * Entry Header
*/
function wellness_coach_lite_article_meta(){ 
    if( is_singular( 'post' ) ) : ?>
        <div class="article-meta">
            <div class="article-meta-inner">
                <?php wellness_coach_lite_posted_by(); ?>
                <?php wellness_coach_lite_comment_count(); ?>
            </div>
        </div>      
        <?php    
    endif;
}
endif;
add_action( 'wellness_coach_lite_before_single_entry_content', 'wellness_coach_lite_article_meta', 17 );

if( ! function_exists( 'wellness_coach_lite_entry_header' ) ) :
/**
 * Entry Header
*/
function wellness_coach_lite_entry_header(){ 
    ?>
    <header class="entry-header">
        <?php 
            
            if( 'post' === get_post_type() ){
                echo '<div class="entry-meta">';                
                wellness_coach_lite_category();
                echo '</div>';
            }               
            
            if ( is_singular() ) :
                the_title( '<h1 class="entry-title">', '</h1>' );
            else :
                the_title( '<h3 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>' );
            endif; 
        
            if( 'post' === get_post_type() ){
                echo '<div class="entry-meta">';                
                wellness_coach_lite_posted_on();
                echo '</div>';
            }		
        ?>
    </header>         
    <?php    
}
endif;
add_action( 'wellness_coach_lite_post_entry_content', 'wellness_coach_lite_entry_header', 10 );
add_action( 'wellness_coach_lite_before_single_entry_content', 'wellness_coach_lite_entry_header', 15 );

if ( ! function_exists( 'wellness_coach_lite_post_thumbnail' ) ) :
/**
 * Displays an optional post thumbnail.
 *
 * Wraps the post thumbnail in an anchor element on index views, or a div
 * element when on single views.
 */
function wellness_coach_lite_post_thumbnail() {

	global $wp_query;
    $image_size     = 'thumbnail';
    $ed_featured    = get_theme_mod( 'ed_featured_image', true );
    $ed_crop_blog   = get_theme_mod( 'ed_crop_blog', false );
    $ed_crop_single = get_theme_mod( 'ed_crop_single', false );
    $sidebar        = wellness_coach_lite_sidebar();
    
    if( is_home() ){        
        if($sidebar){
            $image_size = 'wellness-coach-lite-blog-grid-full';
        }else{
            $image_size = 'wellness-coach-lite-popular';
        }
        echo '<figure class="post-thumbnail"><a href="' . esc_url( get_permalink() ) . '">';
        if( has_post_thumbnail() ){                        
            if( $ed_crop_blog ){
                the_post_thumbnail( 'full', array( 'itemprop' => 'image' ) );    
            }else{
                the_post_thumbnail( $image_size, array( 'itemprop' => 'image' ) );    
            }
        }else{
            wellness_coach_lite_get_fallback_svg( $image_size );//fallback    
        }        
        echo '</a></figure>';
    }elseif( is_archive() || is_search() ) {
        $image_size = 'wellness-coach-lite-blog';
        echo '<figure class="post-thumbnail"><a href="' . esc_url( get_permalink() ) . '">';
        if( has_post_thumbnail() ){                        
            if( $ed_crop_blog ){
                the_post_thumbnail( 'full', array( 'itemprop' => 'image' ) );    
            }else{
                the_post_thumbnail( $image_size, array( 'itemprop' => 'image' ) );    
            }
        }else{
            wellness_coach_lite_get_fallback_svg( $image_size );//fallback    
        }        
        echo '</a></figure>';
    }elseif( is_singular() ){
        if( $sidebar ) {
            $image_size = 'wellness-coach-lite-blog';
        }else{
            $image_size = 'wellness-coach-lite-single-full';
        }
        if( is_single() ){
            if( $ed_featured && has_post_thumbnail() ){
                echo '<figure class="post-thumbnail">';
                if( $ed_crop_single ){
                    the_post_thumbnail( 'full', array( 'itemprop' => 'image' ) );
                }else{
                    the_post_thumbnail( $image_size, array( 'itemprop' => 'image' ) );
                }
                echo '</figure>';    
            }
        }else{
            if( has_post_thumbnail() ){
                echo '<div class="post-thumbnail">';
                the_post_thumbnail( $image_size, array( 'itemprop' => 'image' ) );
                echo '</div>';    
            }            
        }
    }
}
endif;
add_action( 'wellness_coach_lite_before_page_entry_content', 'wellness_coach_lite_post_thumbnail' );
add_action( 'wellness_coach_lite_before_post_entry_content', 'wellness_coach_lite_post_thumbnail', 20 );
add_action( 'wellness_coach_lite_before_single_entry_content', 'wellness_coach_lite_post_thumbnail', 20 );

if( ! function_exists( 'wellness_coach_lite_entry_content' ) ) :
/**
 * Entry Content
*/
function wellness_coach_lite_entry_content(){ 
    $ed_excerpt = get_theme_mod( 'ed_excerpt', true ); 
    if( is_home() ) return false; ?>
    <div class="entry-content" itemprop="text">
		<?php
			if( is_singular() || ! $ed_excerpt || ( get_post_format() != false ) ){
                the_content();    
    			wp_link_pages( array(
    				'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'wellness-coach-lite' ),
    				'after'  => '</div>',
    			) );
            }else{
                the_excerpt();
            }
		?>
	</div><!-- .entry-content -->
    <?php
}
endif;
add_action( 'wellness_coach_lite_page_entry_content', 'wellness_coach_lite_entry_content', 15 );
add_action( 'wellness_coach_lite_post_entry_content', 'wellness_coach_lite_entry_content', 15 );
add_action( 'wellness_coach_lite_single_entry_content', 'wellness_coach_lite_entry_content', 15 );

if( ! function_exists( 'wellness_coach_lite_entry_footer' ) ) :
/**
 * Entry Footer
*/
function wellness_coach_lite_entry_footer(){ 
    $readmore = get_theme_mod( 'read_more_text', __( 'Read More', 'wellness-coach-lite' ) ); 
    if( is_home() ) return false; ?>
	<footer class="entry-footer">
		<?php
			if( is_singular( 'post' ) ){
			    wellness_coach_lite_tag();
			}
            
            if( is_home() || is_archive() || is_search() ){
                echo '<div class="button-wrap"><a href="' . esc_url( get_the_permalink() ) . '" class="btn-link">' . esc_html( $readmore ) . '</a></div>';    
            }
            
            if( get_edit_post_link() ){
                edit_post_link(
					sprintf(
						wp_kses(
							/* translators: %s: Name of current post. Only visible to screen readers */
							__( 'Edit <span class="screen-reader-text">%s</span>', 'wellness-coach-lite' ),
							array(
								'span' => array(
									'class' => array(),
								),
							)
						),
						get_the_title()
					),
					'<span class="edit-link">',
					'</span>'
				);
            }
		?>
	</footer><!-- .entry-footer -->
	<?php 
}
endif;
add_action( 'wellness_coach_lite_page_entry_content', 'wellness_coach_lite_entry_footer', 20 );
add_action( 'wellness_coach_lite_post_entry_content', 'wellness_coach_lite_entry_footer', 20 );
add_action( 'wellness_coach_lite_single_entry_content', 'wellness_coach_lite_entry_footer', 20 );

if( ! function_exists( 'wellness_coach_lite_primary_page_header' ) ) :
/**
 * Page Header
*/
function wellness_coach_lite_primary_page_header(){ 
    $blog_main_title    = get_theme_mod( 'blog_main_title', __( 'From My Blog', 'wellness-coach-lite' ) );
    $blog_main_content  = get_theme_mod( 'blog_main_content' );
    if( is_home() ) return false;
    ?>
    <div class="page-header__content-wrapper">
    <?php
        
        if( is_home() && ( $blog_main_title || $blog_main_content ) ){
            echo '<header class="section-header">';
            if( $blog_main_title ) echo '<h1 class="page-title">' . esc_html( $blog_main_title ) . '</h1>';
            if( $blog_main_content ) {
                echo '<div class="section-desc">
                    ' . wpautop( wp_kses_post( $blog_main_content ) ) . '
                </div>';
            }
            echo '</header>';
        }

        if( is_archive() ){ 
            if( is_author() ){
                $author_name = get_the_author();
                $author_title = get_theme_mod( 'author_title', __( 'About The Author', 'wellness-coach-lite' ) );
                $author_description = get_the_author_meta( 'description' ); ?>
                <div class="author-section">
                    <h3 class="author-section-title">
                        <?php echo esc_html( $author_title ); ?>
                    </h3>
                    <div class="inner-author-section">
                        <div class="author-img-title-wrap">
                            <figure class="author-img"><?php echo get_avatar( get_the_author_meta( 'ID' ), 170 );?></figure>
                            <div class="author-title-wrap">
                                <?php echo '<h1 class="author-name">' . esc_html( $author_name ) . '</h1>'; ?>      
                            </div>
                        </div>
                        <?php echo '<div class="author-content">' . wp_kses_post( wpautop( $author_description ) ) . '</div>'; ?>
                    </div>
                </div>
                <?php 
            }
            else{
                the_archive_title();
                the_archive_description( '<div class="archive-description">', '</div>' );
            }      
        }
        
        if( is_search() ){ 
            echo '<span class="sub-title">' . esc_html__( 'Tagged in', 'wellness-coach-lite' ) . '</span>';
            get_search_form();
        }

        if( is_archive() && !is_author() || is_search() ) wellness_coach_lite_per_page_count();
    ?>
    </div>
    <?php
}
endif;
add_action( 'wellness_coach_lite_before_posts_content', 'wellness_coach_lite_primary_page_header', 10 );

if( ! function_exists( 'wellness_coach_lite_navigation' ) ) :
/**
 * Navigation
*/
function wellness_coach_lite_navigation(){
    if( is_singular() ){
        $next_post = get_next_post();
        $prev_post = get_previous_post();
        $sidebar   = wellness_coach_lite_sidebar();
        $image_size = ( $sidebar ) ? 'wellness-coach-lite-blog-navigation' : 'wellness-coach-lite-blog-grid';

        if( $prev_post || $next_post ){?>            
            <nav class="navigation post-navigation" role="navigation">
    			<h2 class="screen-reader-text"><?php esc_html_e( 'Post Navigation', 'wellness-coach-lite' ); ?></h2>
                <div class="nav-links">
                    <?php if( $prev_post ){ ?>
                        <div class="nav-previous">
                            <article class="post">
                                <figure class="post-thumbnail">
                                    <?php
                                    $prev_img = get_post_thumbnail_id( $prev_post->ID ); ?>
                                    <a href="<?php echo esc_url( get_permalink( $prev_post->ID ) ); ?>" rel="prev">
                                        <?php if( $prev_img ){
                                            $prev_url = wp_get_attachment_image_url( $prev_img, $image_size );
                                            echo '<img src="' . esc_url( $prev_url ) . '" alt="' . the_title_attribute( 'echo=0', $prev_post ) . '">';
                                        }else{
                                            wellness_coach_lite_get_fallback_svg( $image_size );
                                        }
                                        ?>
                                    </a>
                                </figure>
                                <div class="content-wrap">
                                    <div class="entry-meta">
                                        <span class="cat-links" itemprop="about">
                                            <?php
                                            $prev_categories = get_the_category( $prev_post->ID ); 
                                            foreach( $prev_categories as $prev_cat ){
                                                echo '<a href="' . esc_url( get_category_link( $prev_cat->term_id ) ) . '">' . esc_html( $prev_cat->name ) . '</a>';
                                            } ?>
                                        </span> 
                                    </div>
                                    <header class="entry-header">
                                        <a href="<?php echo esc_url( get_permalink( $prev_post->ID ) ); ?>" rel="prev">
                                            <h3 class="entry-title"><?php echo esc_html( get_the_title( $prev_post->ID ) ); ?></h3>                            </a>
                                        </a>
                                    </header>
                                </div>
                            </article>
                            <a href="<?php echo esc_url( get_permalink( $prev_post->ID ) ); ?>" rel="prev">
                                <span class="meta-nav"><?php esc_html_e( 'Previous Articles', 'wellness-coach-lite' ); ?></span>
                            </a>
                        </div>
                    <?php } ?>
                    <?php if( $next_post ){ ?>
                        <div class="nav-next">
                            <article class="post">
                                <figure class="post-thumbnail">
                                    <?php
                                    $next_img = get_post_thumbnail_id( $next_post->ID ); ?>
                                    <a href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>" rel="next">
                                        <?php if( $next_img ){
                                            $next_url = wp_get_attachment_image_url( $next_img, $image_size );
                                            echo '<img src="' . esc_url( $next_url ) . '" alt="' . the_title_attribute( 'echo=0', $next_post ) . '">';
                                        }else{
                                            wellness_coach_lite_get_fallback_svg( $image_size );
                                        }
                                        ?>
                                    </a>
                                </figure>
                                <div class="content-wrap">
                                    <div class="entry-meta">
                                        <span class="cat-links" itemprop="about">
                                            <?php
                                            $next_categories = get_the_category( $next_post->ID ); 
                                            foreach( $next_categories as $next_cat ){
                                                echo '<a href="' . esc_url( get_category_link( $next_cat->term_id ) ) . '">' . esc_html( $next_cat->name ) . '</a>';
                                            } ?>
                                        </span>                                   
                                    </div>
                                    <header class="entry-header">
                                        <a href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>" rel="next">
                                            <h3 class="entry-title"><?php echo esc_html( get_the_title( $next_post->ID ) ); ?></h3>
                                        </a>
                                    </header>
                                </div>
                            </article>
                            <a href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>" rel="prev">
                                <span class="meta-nav"><?php esc_html_e( 'Next Articles', 'wellness-coach-lite' ); ?></span>
                            </a>
                        </div>
                    <?php } ?>
                </div>
    		</nav>       
            <?php
        }
    }else{
            
        the_posts_pagination( array(
            'prev_text'          => __( 'Previous', 'wellness-coach-lite' ),
            'next_text'          => __( 'Next', 'wellness-coach-lite' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'wellness-coach-lite' ) . ' </span>',
        ) );
            
    }
}
endif;
add_action( 'wellness_coach_lite_after_post_content', 'wellness_coach_lite_navigation', 15 );
add_action( 'wellness_coach_lite_after_posts_content', 'wellness_coach_lite_navigation' );

if( ! function_exists( 'wellness_coach_lite_author' ) ) :
/**
 * Author Section
*/
function wellness_coach_lite_author(){ 
    $ed_author    = get_theme_mod( 'ed_author', false );
    $author_name = get_the_author();
    $author_title = get_theme_mod( 'author_title', __( 'About The Author', 'wellness-coach-lite' ) );
    if( ! $ed_author && get_the_author_meta( 'description' ) ){ ?>
    <div class="author-section">
        <h3 class="author-section-title">
            <?php echo esc_html( $author_title ); ?>
        </h3>
        <div class="inner-author-section">
            <div class="author-img-title-wrap">
                <figure class="author-img"><?php echo get_avatar( get_the_author_meta( 'ID' ), 95 ); ?></figure>
                <div class="author-title-wrap">
                    <?php if( $author_name ) echo '<h3 class="author-name">' . esc_html( $author_name ) . '</h3>'; ?>		
                </div>
            </div>
            <?php echo '<div class="author-content">' . wpautop( wp_kses_post( get_the_author_meta( 'description' ) ) ) . '</div>'; ?>
        </div>
    </div>
    <?php
    }
}
endif;
add_action( 'wellness_coach_lite_after_post_content', 'wellness_coach_lite_author', 10 );

if( ! function_exists( 'wellness_coach_lite_newsletter' ) ) :
/**
 * Newsletter
*/
function wellness_coach_lite_newsletter(){ 
    $ed_newsletter = get_theme_mod( 'ed_newsletter', false );
    $newsletter    = get_theme_mod( 'newsletter_shortcode' );
    if( $ed_newsletter && $newsletter ){ ?>
        <div class="newsletter">
            <?php echo do_shortcode( $newsletter ); ?>
        </div>
        <?php
    }
}
endif;
add_action( 'wellness_coach_lite_after_post_content', 'wellness_coach_lite_newsletter', 30 );

if( ! function_exists( 'wellness_coach_lite_related_posts' ) ) :
/**
 * Related Posts 
*/
function wellness_coach_lite_related_posts(){ 
    $ed_related_post = get_theme_mod( 'ed_related', true );
    
    if( $ed_related_post ){
        wellness_coach_lite_get_posts_list( 'related' );    
    }
}
endif;                                                                               
add_action( 'wellness_coach_lite_after_post_content', 'wellness_coach_lite_related_posts', 35 );

if( ! function_exists( 'wellness_coach_lite_popular_posts' ) ) :
/**
 * Popular Posts
*/
function wellness_coach_lite_popular_posts(){ 
    $ed_popular_post = get_theme_mod( 'ed_popular', false );    
    if( $ed_popular_post ){
        wellness_coach_lite_get_posts_list( 'popular' );  
    }
}
endif;
add_action( 'wellness_coach_lite_popular_posts', 'wellness_coach_lite_popular_posts' );

if( ! function_exists( 'wellness_coach_lite_latest_posts' ) ) :
/**
 * Latest Posts
*/
function wellness_coach_lite_latest_posts(){ 
    wellness_coach_lite_get_posts_list( 'latest' );
}
endif;
add_action( 'wellness_coach_lite_latest_posts', 'wellness_coach_lite_latest_posts' );

if( ! function_exists( 'wellness_coach_lite_comment' ) ) :
/**
 * Comments Template 
*/
function wellness_coach_lite_comment(){
    // If comments are open or we have at least one comment, load up the comment template.
	if( get_theme_mod( 'ed_comments', true ) && ( comments_open() || get_comments_number() ) ) :
		comments_template();
	endif;
}
endif;
add_action( 'wellness_coach_lite_after_post_content', 'wellness_coach_lite_comment', wellness_coach_lite_comment_toggle() );
add_action( 'wellness_coach_lite_after_page_content', 'wellness_coach_lite_comment' );

if( ! function_exists( 'wellness_coach_lite_content_end' ) ) :
/**
 * Content End
*/
function wellness_coach_lite_content_end(){ 
    $home_sections = wellness_coach_lite_get_home_sections(); 
    if( ! ( is_front_page() && ! is_home() && $home_sections ) ){ ?>            
        </div><!-- .container/ -->        
    </div><!-- .error-holder/site-content -->
    <?php
    }
}
endif;
add_action( 'wellness_coach_lite_before_footer', 'wellness_coach_lite_content_end', 20 );


if( ! function_exists( 'wellness_coach_lite_instagram' ) ) :
/**
 * Before Footer
*/
function wellness_coach_lite_instagram(){ 
    $ed_instagram = get_theme_mod( 'ed_instagram', false );
    $insta_code   = get_theme_mod('instagram_shortcode', '[instagram-feed]');
    if( $ed_instagram ){
        echo '<div class="instagram-section">';
        echo do_shortcode( $insta_code );
        echo '</div>';    
    }
}
endif;
add_action( 'wellness_coach_lite_before_footer', 'wellness_coach_lite_instagram', 30 );

if( ! function_exists( 'wellness_coach_lite_footer_start' ) ) :
/**
 * Footer Start
*/
function wellness_coach_lite_footer_start(){
    ?>
    <footer id="colophon" class="site-footer" itemscope itemtype="http://schema.org/WPFooter">
    <?php
}
endif;
add_action( 'wellness_coach_lite_footer', 'wellness_coach_lite_footer_start', 20 );

if( ! function_exists( 'wellness_coach_lite_footer_top' ) ) :
/**
 * Footer Top
*/
function wellness_coach_lite_footer_top(){ ?>
    <div class="footer-top">
        <div class="container">
            <div class="footer-brand-area">
                <?php wellness_coach_lite_site_branding(); ?>
                <?php wellness_coach_lite_footer_navigation(); ?>
            </div>
        </div>
    </div>
    <?php 
}
endif;
add_action( 'wellness_coach_lite_footer', 'wellness_coach_lite_footer_top', 25 );

if( ! function_exists( 'wellness_coach_lite_footer_mid' ) ) :
/**
 * Footer Mid
*/
function wellness_coach_lite_footer_mid(){    
    $footer_sidebars = array( 'footer-one', 'footer-two', 'footer-three', 'footer-four' );
    $active_sidebars = array();
    $sidebar_count   = 0;
    
    foreach ( $footer_sidebars as $sidebar ) {
        if( is_active_sidebar( $sidebar ) ){
            array_push( $active_sidebars, $sidebar );
            $sidebar_count++ ;
        }
    }
                 
    if( $active_sidebars ){ ?>
        <div class="footer-mid">
            <div class="container">
                <div class="grid column-<?php echo esc_attr( $sidebar_count ); ?>">
                <?php foreach( $active_sidebars as $active ){ ?>
                    <div class="col">
                       <?php dynamic_sidebar( $active ); ?> 
                    </div>
                <?php } ?>
                </div>
            </div>
        </div>
        <?php 
    }
}
endif;
add_action( 'wellness_coach_lite_footer', 'wellness_coach_lite_footer_mid', 30 );

if( ! function_exists( 'wellness_coach_lite_footer_bottom' ) ) :
/**
 * Footer Bottom
*/
function wellness_coach_lite_footer_bottom(){ ?>
    <div class="footer-bottom">
		<div class="container">
            <div class="footer-bottom__content-wrapper">
    			<div class="site-info">            
                <?php
                    wellness_coach_lite_get_footer_copyright();
                    echo esc_html__( ' Wellness Coach Lite | Developed By ', 'wellness-coach-lite' ); 
                    echo '<a href="' . esc_url( 'https://blossomthemes.com' ) .'" rel="nofollow" target="_blank">' . esc_html__( 'Blossom Themes', 'wellness-coach-lite' ) . '</a>.';                
                    printf( esc_html__( ' Powered by %s. ', 'wellness-coach-lite' ), '<a href="'. esc_url( __( 'https://wordpress.org/', 'wellness-coach-lite' ) ) .'" target="_blank">WordPress</a>' );
                    if( function_exists( 'the_privacy_policy_link' ) ){
                        the_privacy_policy_link();
                    }
                ?>               
                </div>
                <?php if( wellness_coach_lite_social_links( false ) ) : 
                    echo '<div class="footer-social-network">';
                    wellness_coach_lite_social_links(); 
                    echo '</div>';
                endif; ?>
            </div>
		</div>
        <button class="back-to-top">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M6.101 359.293L25.9 379.092c4.686 4.686 12.284 4.686 16.971 0L224 198.393l181.13 180.698c4.686 4.686 12.284 4.686 16.971 0l19.799-19.799c4.686-4.686 4.686-12.284 0-16.971L232.485 132.908c-4.686-4.686-12.284-4.686-16.971 0L6.101 342.322c-4.687 4.687-4.687 12.285 0 16.971z"></path></svg>
        </button><!-- .back-to-top -->
	</div>
    <?php
}
endif;
add_action( 'wellness_coach_lite_footer', 'wellness_coach_lite_footer_bottom', 40 );

if( ! function_exists( 'wellness_coach_lite_footer_end' ) ) :
/**
 * Footer End 
*/
function wellness_coach_lite_footer_end(){ ?>
    </footer><!-- #colophon -->
    <?php
}
endif;
add_action( 'wellness_coach_lite_footer', 'wellness_coach_lite_footer_end', 50 );

if( ! function_exists( 'wellness_coach_lite_page_end' ) ) :
/**
 * Page End
*/
function wellness_coach_lite_page_end(){ ?>
    </div><!-- #page -->
    <?php
}
endif;
add_action( 'wellness_coach_lite_after_footer', 'wellness_coach_lite_page_end', 20 );