<?php
/**
 * Feminine Lifestyle Blog Template Functions which enhance the theme by hooking into WordPress
 *
 * @package Feminine_Lifestyle_Blog
 */

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

if( ! function_exists( 'feminine_lifestyle_blog_head' ) ) :
/**
 * Before wp_head 
*/
function feminine_lifestyle_blog_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( 'feminine_lifestyle_blog_before_wp_head', 'feminine_lifestyle_blog_head' );

if( ! function_exists( 'feminine_lifestyle_blog_page_start' ) ) :
/**
 * Page Start
*/
function feminine_lifestyle_blog_page_start(){ ?>
    <div id="page" class="site">
        <a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to Content', 'feminine-lifestyle-blog' ); ?></a>
    <?php
}
endif;
add_action( 'feminine_lifestyle_blog_before_header', 'feminine_lifestyle_blog_page_start', 20 );

if( ! function_exists( 'feminine_lifestyle_blog_header' ) ) :
/**
 * Header Start
*/
function feminine_lifestyle_blog_header(){ 
    ?>
    <header id="masthead" class="site-header style-three" itemscope itemtype="http://schema.org/WPHeader">
        <div class="header-top">
            <div class="container">
                <div class="header-left">		
                    <?php 
                    feminine_lifestyle_blog_secondary_navigation();
                    feminine_lifestyle_blog_social_links(); ?>
                </div>
                <div class="header-right">
                    <?php 
                    feminine_lifestyle_blog_search_func(); 
                    ?>
                </div>
            </div>
        </div>
        <div class="header-main">
            <div class="container">
                <?php 
                feminine_lifestyle_blog_site_branding(); 
                feminine_lifestyle_blog_primary_navigation(); ?>
            </div>
        </div>
        <?php feminine_lifestyle_blog_mobile_navigation(); ?>
    </header>
    <?php
}
endif;
add_action( 'feminine_lifestyle_blog_header', 'feminine_lifestyle_blog_header', 20 );

if( ! function_exists( 'feminine_lifestyle_blog_banner' ) ) :
/**
 * Banner Section 
*/
function feminine_lifestyle_blog_banner(){
    if( is_front_page() || is_home() ) feminine_lifestyle_blog_get_banner();   
}
endif;
add_action( 'feminine_lifestyle_blog_after_header', 'feminine_lifestyle_blog_banner', 10 );

if( ! function_exists( 'feminine_lifestyle_blog_about_sec' ) ) :
/**
 * About Section
*/
function feminine_lifestyle_blog_about_sec(){
    $ed_section   = get_theme_mod( 'ed_about_section', false );
    $sec_title    = get_theme_mod( 'about_title', esc_html__( 'About Me', 'feminine-lifestyle-blog' ) );
    $sec_content  = get_theme_mod( 'about_content');
    $abt_sign_img = get_theme_mod( 'abt_signature_image' );
    $abt_img      = get_theme_mod( 'abt_image' );
    $abt_btn_lbl  = get_theme_mod( 'about_btn_label' );
    $abt_btn_url  = get_theme_mod( 'about_btn_url' );
    $abt_img_align = get_theme_mod( 'about_image_align', 'left-align' );

    if( is_home() && $ed_section && ( $sec_title || $sec_content || $abt_sign_img || $abt_img ) ){ ?>
        <section id="about_section" class="about-section section">
            <div class="container">
                <div class="about-section-wrapper">                
                    <div class="about-grid <?php echo esc_attr( $abt_img_align ); ?>"> 
                        <?php if( $abt_img ){
                            echo '<div class="about-thumbnail grid-item">' . wp_get_attachment_image( $abt_img, 'feminine-lifestyle-blog-about-sec', false, array( 'itemprop' => 'image' ) ) . '</div>';
                        }
                        if( $sec_title || $sec_content || $abt_sign_img || ( $abt_btn_lbl && $abt_btn_url ) ){
                            echo '<div class="content-box grid-item">';
                                if( $sec_title ) echo '<h2 class="about-section-title" itemprop="name">' . esc_html( $sec_title ) . '</h2>';                                        
                                if( $sec_content ) echo '<div class="about_content">' . wp_kses_post(wpautop( $sec_content ) ) . '</div>';
                                if( $abt_sign_img ) echo '<div class="signature-here">' .  wp_get_attachment_image( $abt_sign_img, 'full', false, array( 'itemprop' => 'image' ) ) . '</div>';
                                if( $abt_btn_lbl && $abt_btn_url ) echo '<a href="' . esc_url( $abt_btn_url ) . '" target="_blank" class="primary-btn">' . esc_html( $abt_btn_lbl ) . '</a>';
                            echo '</div>';
                        } ?>
                    </div>
                </div>  
            </div>
         </section>
    <?php }
}
endif;
add_action( 'feminine_lifestyle_blog_after_header', 'feminine_lifestyle_blog_about_sec', 20 );

if( ! function_exists( 'feminine_lifestyle_blog_top_bar' ) ) :
/**
 * Top bar for single page and post
 * 
*/
function feminine_lifestyle_blog_top_bar(){
    if( !( is_front_page() || is_home() ) && ( is_singular( 'page' ) || is_archive() ) ){ ?>
        <div class="top-bar">
    		<div class="container">
            <?php
                //Breadcrumb
                feminine_lifestyle_blog_breadcrumb(); 
            ?>
    		</div>
    	</div>   
        <?php 
    }    
}
endif;
add_action( 'feminine_lifestyle_blog_after_header', 'feminine_lifestyle_blog_top_bar', 30 );

if( ! function_exists( 'feminine_lifestyle_blog_content_start' ) ) :
/**
 * Content Start
 *  
*/
function feminine_lifestyle_blog_content_start(){    

    echo '<div id="content" class="site-content">';

    if( has_post_thumbnail() ){
        $thumbnail_class = '';
    }else{
        $thumbnail_class = 'no-thumbnail';
    }

    if( is_singular( 'post' ) ){ ?>
        <div class="page-header"<?php echo esc_attr( $thumbnail_class ); ?>>
            <?php 
                echo '<div class="container"><div class="breadcrumb-wrapper">';      
                //Breadcrumb
                feminine_lifestyle_blog_breadcrumb();
                echo '</div></div>';
    
                //Single Post Header Layout
                feminine_lifestyle_blog_single_layout();
            ?>
        </div>
    <?php }
    if( !is_404() ) echo '<div class="container">';
}
endif;
add_action( 'feminine_lifestyle_blog_content', 'feminine_lifestyle_blog_content_start' );

if( ! function_exists( 'feminine_lifestyle_blog_search_per_page_count' ) ):
/**
*   Counts the Number of total posts in Archive, Search and Author
*/
function feminine_lifestyle_blog_search_per_page_count(){
    $pagination = get_theme_mod( 'pagination_type','numbered' );
    global $wp_query;
    if( is_archive() || is_search() && $wp_query->found_posts > 0 ) {
        $posts_per_page = get_option( 'posts_per_page' );
        $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
        $start_post_number = 0;
        $end_post_number   = 0;

        if( $wp_query->found_posts > 0 ):                
            $start_post_number = 1;
            if( $wp_query->found_posts < $posts_per_page  ) {
                $end_post_number = $wp_query->found_posts;
            }else{
                $end_post_number = $posts_per_page;
            }

            if( $paged > 1 ){
                $start_post_number = $posts_per_page * ( $paged - 1 ) + 1;
                if( $wp_query->found_posts < ( $posts_per_page * $paged )  ) {
                    $end_post_number = $wp_query->found_posts;
                }else{
                    $end_post_number = $paged * $posts_per_page;
                }
            }

            printf( esc_html__( '%1$s Showing:  %2$s - %3$s of %4$s RESULTS %5$s', 'feminine-lifestyle-blog' ), '<span class="result-count">', absint( $start_post_number ), absint( $end_post_number ), esc_html( number_format_i18n( $wp_query->found_posts ) ), '</span>' );
        endif;
    }
}
endif; 

if( ! function_exists( 'feminine_lifestyle_blog_entry_header' ) ) :
/**
 * Entry Header
*/
function feminine_lifestyle_blog_entry_header(){ 

    global $wp_query;
    
    if ( is_home() || is_archive() || is_search() ) {
        if( (  $wp_query->current_post == 0 ) ) return false;
    }

    if ( is_home() || is_archive() || is_search() ){
        ?>
        <header class="entry-header">
    		<?php                    
            if( 'post' === get_post_type() ){
                if ( ( is_home() || is_archive() || is_search() ) ) feminine_lifestyle_blog_posted_on(); 
                feminine_lifestyle_blog_category();
            }	
            the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
    	</header> 
    <?php }  
}
endif;
add_action( 'feminine_lifestyle_blog_post_entry_content', 'feminine_lifestyle_blog_entry_header', 10 );

if ( ! function_exists( 'feminine_lifestyle_blog_entry_first_header' ) ) :
/**
* Entry Header
*/
function feminine_lifestyle_blog_entry_first_header(){
    global $wp_query;

    if ( ( is_home() || is_archive() || is_search() ) && $wp_query->current_post == 0  ) {
        feminine_lifestyle_blog_entry_header_first();
    }

    if ( is_page() ) {
        ?>
        <header class="page-header">
            <h1 class="page-title"><?php the_title(); ?></h1>
        </header> 
        <?php
    }

}
endif;
add_action( 'feminine_lifestyle_blog_before_page_entry_content', 'feminine_lifestyle_blog_entry_first_header', 10 );
add_action( 'feminine_lifestyle_blog_before_post_entry_content', 'feminine_lifestyle_blog_entry_first_header', 10 ); 

if ( ! function_exists( 'feminine_lifestyle_blog_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 feminine_lifestyle_blog_post_thumbnail() {
	global $wp_query;
    $image_size  = 'thumbnail';
    $sidebar     = feminine_lifestyle_blog_sidebar();
    $ed_crop_blog = get_theme_mod( 'ed_crop_blog', false );

    if( is_home() || is_archive() || is_search() ){        
      
        if( $wp_query->current_post == 0 ) :                
            $image_size = ( $sidebar ) ? 'feminine-lifestyle-blog-one' : 'feminine-lifestyle-blog-slider-one';
        else:
            $image_size = ( $sidebar ) ? 'feminine-lifestyle-blog-sm' : 'feminine-lifestyle-blog-sidebar';
        endif;
        

        if ( has_post_thumbnail() ) {
            echo '<figure class="post-thumbnail"><a href="' . esc_url( get_permalink() ) . '" class="post-thumbnail">';

                if ( ! $ed_crop_blog ) {
                    the_post_thumbnail( $image_size, array( 'itemprop' => 'image' ) );
                }else{
                    the_post_thumbnail();
                }
            echo '</a></figure>';
        }else{
            echo '<figure class="post-thumbnail"><a href="' . esc_url( get_permalink() ) . '" class="post-thumbnail">';
                feminine_lifestyle_blog_get_fallback_svg( $image_size );//fallback
            echo '</a></figure>';
        }

    }elseif( is_page() ){
        echo '<figure class="post-thumbnail">';
            $image_size = ( $sidebar ) ? 'feminine-lifestyle-blog-sidebar' : 'feminine-lifestyle-blog-slider-one';
            the_post_thumbnail( $image_size, array( 'itemprop' => 'image' ) ); 
        echo '</figure>';
    }
}
endif;
add_action( 'feminine_lifestyle_blog_before_page_entry_content', 'feminine_lifestyle_blog_post_thumbnail', 20 );
add_action( 'feminine_lifestyle_blog_before_post_entry_content', 'feminine_lifestyle_blog_post_thumbnail', 20 );

if( ! function_exists( 'feminine_lifestyle_blog_entry_content' ) ) :
/**
 * Entry Content
*/
function feminine_lifestyle_blog_entry_content(){ 
    $ed_excerpt = get_theme_mod( 'ed_excerpt', true );

    if ( is_home() || is_archive() || is_search() || is_singular() ) {

        if ( is_home() || is_archive() || is_search() ) echo '<div class="content-wrap">';

            echo '<div class="entry-content" itemprop="text">';
                if( is_singular() || ! $ed_excerpt || ( get_post_format() != false ) ){
                    the_content();    
                    wp_link_pages( array(
                        'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'feminine-lifestyle-blog' ),
                        'after'  => '</div>',
                    ) );
                }else{
                    the_excerpt();
                }

            echo '</div>';            

        if ( is_home() || is_archive() || is_search() ) echo '</div>';

    }    
}
endif;
add_action( 'feminine_lifestyle_blog_page_entry_content', 'feminine_lifestyle_blog_entry_content', 15 );
add_action( 'feminine_lifestyle_blog_post_entry_content', 'feminine_lifestyle_blog_entry_content', 15 );
add_action( 'feminine_lifestyle_blog_single_post_entry_content', 'feminine_lifestyle_blog_entry_content', 15 );


if( ! function_exists( 'feminine_lifestyle_blog_entry_footer' ) ) :
/**
 * Entry Footer
*/
function feminine_lifestyle_blog_entry_footer(){

    $ed_excerpt = get_theme_mod( 'ed_excerpt', true ); 
    $readmore   = get_theme_mod( 'read_more_text', __( 'Read More', 'feminine-lifestyle-blog' ) ); 

    if ( is_home() || is_archive() || is_search() || is_single() ) { 
 
        echo '<div class="entry-footer">';

            if ( is_single() ) feminine_lifestyle_blog_tag();

            if( $ed_excerpt && $readmore && !empty( get_the_content() ) && ! is_single() ){

                echo '<div class="button-wrap"><a href="' . esc_url( get_the_permalink() ) . '" class="secondary-btn">' . 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>', 'feminine-lifestyle-blog' ),
                            array(
                                'span' => array(
                                    'class' => array(),
                                ),
                            )
                        ),
                        get_the_title()
                    ),
                    '<span class="edit-link">',
                    '</span>'
                );
            }            

        echo '</div>';
    }
}
endif;
add_action( 'feminine_lifestyle_blog_post_entry_content', 'feminine_lifestyle_blog_entry_footer', 20 );
add_action( 'feminine_lifestyle_blog_single_post_entry_content', 'feminine_lifestyle_blog_entry_footer', 20 );

if( ! function_exists( 'feminine_lifestyle_blog_navigation' ) ) :
/**
 * Navigation
*/
function feminine_lifestyle_blog_navigation(){

    if( is_singular() ){

        $prev_post = get_previous_post();
        $next_post = get_next_post();

        if( $prev_post || $next_post ){ ?>            
            <nav class="post-navigation navigation" role="navigation">
                <h2 class="screen-reader-text"><?php esc_html_e( 'Post Navigation', 'feminine-lifestyle-blog' ); ?></h2>
                <div class="nav-links">
                    <?php if( $prev_post ){ ?>
                        <div class="nav-previous">
                            <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, 'thumbnail' );
                                        echo '<img src="' . esc_url( $prev_url ) . '" alt="' . the_title_attribute( 'echo=0', $prev_post ) . '">';                                        
                                    }else{
                                        feminine_lifestyle_blog_get_fallback_svg( 'thumbnail' );
                                    } ?>
                                </a>
                            </figure>
                            <a href="<?php echo esc_url( get_permalink( $prev_post->ID ) ); ?>" rel="prev">
                                <span class="meta-nav"><?php esc_html_e( 'Previous Article', 'feminine-lifestyle-blog' ); ?></span>
                                <article class="post">
                                    <div class="content-wrap">
                                        <header class="entry-header">
                                            <h3 class="entry-title"><?php echo esc_html( get_the_title( $prev_post->ID ) ); ?></h3>
                                        </header>
                                    </div>
                                </article>
                            </a>
                        </div>
                    <?php }
                    if( $next_post ){ ?>
                    <div class="nav-next">
                        <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, 'thumbnail' );
                                    echo '<img src="' . esc_url( $next_url ) . '" alt="' . the_title_attribute( 'echo=0', $next_post ) . '">';                                        
                                }else{
                                    feminine_lifestyle_blog_get_fallback_svg( 'thumbnail' );
                                } ?>
                            </a>
                        </figure>
                        <a href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>" rel="prev">
                            <span class="meta-nav"><?php esc_html_e( 'Next Article', 'feminine-lifestyle-blog' ); ?></span>
                            <article class="post">
                                <div class="content-wrap">
                                    <header class="entry-header">
                                        <h3 class="entry-title"><?php echo esc_html( get_the_title( $next_post->ID ) ); ?></h3>
                                    </header>
                                </div>
                            </article>
                        </a>
                    </div>
                    <?php } ?>
                </div>
            </nav>        
            <?php
        }
    }else{
        $pagination = get_theme_mod( 'pagination_type', 'numbered' );
        
        switch( $pagination ){
            case 'default': // Default Pagination
            
            the_posts_navigation();
            
            break;
            
            case 'numbered': // Numbered Pagination
            
            the_posts_pagination( array(
                'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'feminine-lifestyle-blog' ) . ' </span>',
            ) );
            
            break;
            
            default:
            
            the_posts_navigation();
            
            break;
        }        
    }
}
endif;
add_action( 'feminine_lifestyle_blog_after_post_content', 'feminine_lifestyle_blog_navigation', 20 );
add_action( 'feminine_lifestyle_blog_after_posts_content', 'feminine_lifestyle_blog_navigation' );

if( ! function_exists( 'feminine_lifestyle_blog_author' ) ) :
/**
 * Author Section
*/
function feminine_lifestyle_blog_author(){

    $author_title = get_theme_mod( 'author_title', __( 'About Author', 'feminine-lifestyle-blog' ) );
    if( get_the_author_meta( 'description' ) ){ ?>
        <div class="author-section">
            <?php  if( $author_title ) echo '<h3 class="author-section-title">' . 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, '', 'avatar' ); ?>
                    </figure>
                    <div class="author-title-wrap">
                        <?php feminine_lifestyle_blog_posted_by(); ?>
                    </div>
                </div>
                <div class="author-content">
                    <?php echo wp_kses_post( wpautop( get_the_author_meta( 'description' ) ) ); ?>
                </div>
            </div>
        </div>
    <?php
    }
}
endif;
add_action( 'feminine_lifestyle_blog_after_post_content', 'feminine_lifestyle_blog_author', 15 );

if( ! function_exists( 'feminine_lifestyle_blog_newsletter' ) ) :
/**
 * Newsletter
*/
function feminine_lifestyle_blog_newsletter(){ 
    $ed_newsletter  = get_theme_mod( 'ed_newsletter', false );
    $newsletter     = get_theme_mod( 'newsletter_shortcode' );
    $newsletter_img = get_theme_mod( 'newsletter_image' );
    $newsletter_title   = get_theme_mod( 'newsletter_title', __( 'Sign up now!', 'feminine-lifestyle-blog' ) );
    $newsletter_content = get_theme_mod( 'newsletter_content' );

    if( feminine_lifestyle_blog_is_wpforms_lite_activated() && $ed_newsletter && $newsletter && (is_home() && is_front_page()) ){ ?>
        <div id="newsletter_section" class="newsletter-section section">
            <div class="container">
                <div class="newsletter-section-grid">
                    <?php if( $newsletter_img ){ ?>
                        <div class="grid-item">             
                            <?php echo wp_get_attachment_image( $newsletter_img, 'feminine-lifestyle-newsletter', false, array( 'itemprop' => 'image' ) ); ?>
                        </div>
                    <?php } ?>
                    <div class="grid-item">
                        <div class="newsletter-content">
                            <?php 
                                if ( $newsletter_title || $newsletter_content ) {
                                    echo '<div class="section-header">';
                                    if ( $newsletter_title ) echo '<h2 class="section-title">' . esc_html( $newsletter_title ) . '</h2>';
                                    if ( $newsletter_content ) echo '<div class="section-desc">' . wp_kses_post( wpautop($newsletter_content) ) . '</div>';
                                    echo '</div>'; 
                                }
                                echo do_shortcode( $newsletter ); 
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }
}
endif;
add_action( 'feminine_lifestyle_blog_footer', 'feminine_lifestyle_blog_newsletter', 10 );

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


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

if( ! function_exists( 'feminine_lifestyle_blog_comment' ) ) :
/**
 * Comments Template 
*/
function feminine_lifestyle_blog_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( 'feminine_lifestyle_blog_after_post_content', 'feminine_lifestyle_blog_comment', 45 );
add_action( 'feminine_lifestyle_blog_after_page_content', 'feminine_lifestyle_blog_comment' );

if( ! function_exists( 'feminine_lifestyle_blog_content_end' ) ) :
/**
 * Content End
*/
function feminine_lifestyle_blog_content_end(){ 
        if ( !is_404() ) echo '</div>'; ?><!-- .container/ -->        
    </div><!-- .error-holder/site-content -->
    <?php
}
endif;
add_action( 'feminine_lifestyle_blog_before_footer', 'feminine_lifestyle_blog_content_end', 20 );

if( ! function_exists( 'feminine_lifestyle_blog_instagram_section' ) ) :
/**
 * Bottom Instagram Section
*/
function feminine_lifestyle_blog_instagram_section(){ 
    if( feminine_lifestyle_blog_is_sbif_activated() ){
        $ed_instagram        = get_theme_mod( 'ed_instagram', false );
        $instagram_title     = get_theme_mod( 'instagram_title',__( 'Instagram', 'feminine-lifestyle-blog' ) );
        $instagram_shortcode = get_theme_mod( 'instagram_shortcode' );

        if( $ed_instagram && ($instagram_title || $instagram_shortcode) ){ ?>
            <section id="instagram_section" class="instagram-section section">
                <div class="container">
                    <div class="section-header">
                        <?php if( $instagram_title ){ ?>
                            <h2 class="section-title">
                                <?php echo esc_html( $instagram_title ); ?>
                            </h2>
                        <?php } ?>
                    </div>
                    <?php if( $instagram_shortcode ){ ?>
                        <div class="instagram-inner-wrap">
                            <?php echo do_shortcode( $instagram_shortcode ); ?>
                        </div>
                    <?php } ?>
                </div>
            </section>
        <?php }
    }
}
endif;
add_action( 'feminine_lifestyle_blog_footer', 'feminine_lifestyle_blog_instagram_section', 15 );

if( ! function_exists( 'feminine_lifestyle_blog_cta_section' ) ) :
/**
 * Bottom CTA section
*/
function feminine_lifestyle_blog_cta_section(){ 
    $ed_section    = get_theme_mod( 'ed_cta_section', false );
    $sec_title     = get_theme_mod( 'cta_title', esc_html__( 'Ready to explore exciting adventures?', 'feminine-lifestyle-blog' ) );
    $sec_content   = get_theme_mod( 'cta_content');
    $cta_img       = get_theme_mod( 'cta_image' );
    $cta_btn_lbl   = get_theme_mod( 'cta_btn_label' );
    $cta_btn_url   = get_theme_mod( 'cta_btn_url' );

    if( $ed_section && ( $sec_title || $sec_content || $cta_img || $cta_btn_lbl ) ){ ?>
        <section id="cta_section" class="cta-section section <?php if( $cta_img ) echo 'cta-image'; ?>">
            <?php if( $cta_img ){
                echo '<div class="cta-bg-image">' . wp_get_attachment_image( $cta_img, 'full', false, array( 'itemprop' => 'image' ) ) . '</div>';
            } ?>
            <div class="container">
                <div class="cta-section-wrapper">
                    <?php
                    if( $sec_title || $sec_content || ( $cta_btn_lbl && $cta_btn_url ) ){
                        echo '<div class="content-box center-align">';
                            if( $sec_title ) echo '<h2 class="cta-section-title" itemprop="name">' . esc_html( $sec_title ) . '</h2>';                                        
                            if( $sec_content ) echo '<div class="cta_content">' . wp_kses_post(wpautop( $sec_content ) ) . '</div>';
                            if( $cta_btn_lbl && $cta_btn_url ) echo '<a href="' . esc_url( $cta_btn_url ) . '" target="_blank" class="primary-btn">' . esc_html( $cta_btn_lbl ) . '</a>';
                        echo '</div>';
                    } ?>
                </div>  
            </div>
        </section>
    <?php }
}
endif;
add_action( 'feminine_lifestyle_blog_footer', 'feminine_lifestyle_blog_cta_section', 20 );

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

if( ! function_exists( 'feminine_lifestyle_blog_footer_top' ) ) :
/**
 * Footer Top
*/
function feminine_lifestyle_blog_footer_top(){    
    $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-t">
    		<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( 'feminine_lifestyle_blog_footer', 'feminine_lifestyle_blog_footer_top', 30 );

if( ! function_exists( 'feminine_lifestyle_blog_footer_bottom' ) ) :
/**
 * Footer Bottom
*/
function feminine_lifestyle_blog_footer_bottom(){ ?>
    <div class="footer-b">
        <div class="container">
            <div class="copyright">
                <?php 
                echo '<span class="copyright-text">';
                feminine_lifestyle_blog_get_footer_copyright();
                echo '</span>';
                feminine_lifestyle_blog_ed_author_link();
                feminine_lifestyle_blog_ed_wp_link();
                if( function_exists( 'the_privacy_policy_link' ) ){
                    the_privacy_policy_link();
                } ?>    
            </div>
            <div class="footer-social">
                <?php feminine_lifestyle_blog_social_links(); ?>
            </div>
        </div>
    </div> <!-- .footer-b -->
    <?php
}
endif;
add_action( 'feminine_lifestyle_blog_footer', 'feminine_lifestyle_blog_footer_bottom', 40 );

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

if( ! function_exists( 'feminine_lifestyle_blog_back_to_top' ) ) :
/**
 * Back to top
*/
function feminine_lifestyle_blog_back_to_top(){ ?>
    <button class="back-to-top">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g transform="translate(-1789 -1176)"><rect width="24" height="2.667" transform="translate(1789 1176)" fill="#fff"/><path d="M-215.453,382.373-221.427,372l-5.973,10.373h4.64v8.293h2.667v-8.293Z" transform="translate(2022.427 809.333)" fill="#fff"/></g></svg>
    </button>
    <?php
}
endif;
add_action( 'feminine_lifestyle_blog_after_footer', 'feminine_lifestyle_blog_back_to_top', 15 );

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